请大神用Python编写一个做题程序,如何读取一个question(题目).txt和answer(答案).txt,并提示对,错

Python015

请大神用Python编写一个做题程序,如何读取一个question(题目).txt和answer(答案).txt,并提示对,错,第1张

先读取文件。

假如你的答案是2,判定代码是:

answer = input("输入你的答案:")

if answer == 2:

print("正确")

if answer != 2:

print("错误!")

#!/usr/bin/envpythonimportsysstr=Truewhile(str):dig=int(input())ifdig>100:print'pleaseinputmunbetween0~100'elifdig>=90:print'A'elifdig>=80:print'B'elifdig>=70:print'C'elifdig>=60:prin

第10不知道是啥。

# 计算圆的面积

import math

r = float(input('请输入圆的半径: '))

area = r**2 * math.pi

print(area)

# 反向输出3位数

str = input('请输入一个三位整数')

new_str = str[::-1]

print(new_str)

# 预测身高

while True:

    type = input('请选择测试男女,男孩输入1,女孩输入2: ')

    if type == '1' or type == '2':

        break

f_height = float(input('请输入爸爸身高: '))

m_height = float(input('请输入妈妈身高: '))

if type == '1':

    height = (f_height + m_height) * 1.08 / 2

    print('预测男孩身高为: {}'.format(math.floor(height) ))

elif type == '2':

    height = (f_height * 0.823 + m_height) / 2

    print('预测女孩身高为: {}'.format(math.floor(height)))

else:

    print('预测对象选择错误,请重新启动程序选择。')

# 实数绝对值

import re

import math

while True:

    try:

        num = input('请输入一个实数: ')

        num = int(num)

        break

    except ValueError:

        try:

            num = float(num)

            break

        except ValueError:

            continue

# 使用 abs

num_abs = abs(num)

print('该实数绝对值为: {}'.format(num_abs))

# 使用判断

if num >= 0:

    num_abs = num

else:

    num_abs = -num

print('该实数绝对值为: {}'.format(num_abs))

# 判断年份是否为闰年

while True:

    try:

        year = int(input('请输入一个年份: '))

        break

    except ValueError:

        print('输入错误,年份为整数,请重新输入')

        continue

if (year % 100 == 0):

    if (year % 400 == 0):

        print('年份{}为闰年'.format(year))

    else:

        print('年份{}为平年'.format(year))

elif (year % 4 == 0):

    print('年份{}为闰年'.format(year))

else:

    print('年份{}为平年'.format(year))

# 缴纳学费

while True:

    try:

        I = int(input('请输入学生学号: '))

        break

    except ValueError:

        print('输入错误')

        continue

while True:

    try:

        U = int(input('请输入该学生学分: '))

        break

    except ValueError:

        print('输入错误')

        continue

if U <= 12:

    T = 4000

else:

    T = 4000 + 200 * (U - 12)

print('学生 {} 应缴纳学分为 {}'.format(I, T))

# 登录

username = '123'

password = '456'

while True:

    user = input('请输入用户名: ')

    pw = input('请输入密码: ')

    if (user == username and pw == password):

        print('欢迎使用!')

        break

    else:

        print('用户名或密码错误,请重新输入!')

# 判断输入字符

while True:

    str = input('请输入一个字符')

    if (len(str) == 1):

        break

    else:

        print('输入错误,请重新输入')

str_code = ord(str)

if str_code >= 48 and str_code <= 57:

    print('{} 是一个数字'.format(str))

elif str_code >= 65 and str_code <= 90:

    print('{} 是一个大写字母'.format(str))

elif str_code >= 97 and str_code <= 122:

    print('{} 是一个小写字母'.format(str))

else:

    print('{} 既不是数字,也不是大小写字母'.format(str))

# 判断成绩

while True:

    try:

        grade = int(input('请输入成绩: '))

        if (grade >= 0 and grade <= 100):

            break

        else:

            print('成绩输入错误,请重新输入')

            continue

    except ValueError:

        print('成绩输入错误,请重新输入')

        continue

if grade>= 90:

    print('优秀')

elif grade >= 80:

    print('良好')

elif grade >= 70:

    print('中等')

elif grade >= 60:

    print('及格')

else:

    print('不及格')