基本要求如下:
1、用户自行输入题目数量n,系统自动按照题目难度,为每一个题目赋分,总分为100分。
2、系统随机生成四则运算表达式,让用户计算,如:1+1=?,2/4=?,27557+67/79+29*37-49,等
3、系统自动对用户计算结果判断对错,如1+1=2:√,2/4=8:×
4、系统自动计算并返回用户最终得分和测试所用时长。
参考代码
import random
n = int(input("请输入题目数量:"))
op = ['+','-','*','/']
tsc = 0
sc = 0
lis = []
for i in range(n):
c = random.randint(1,5)
calc = str(random.randint(1,100))
t = 0
for j in range(c):
p = random.randint(0,3)
t += 2 if p<2 else 3
calc += op[p]
calc += str(random.randint(1,100))
lis.append([calc,t])
tsc += t
for i,(calc,t) in enumerate(lis):
g = float(input(f"第{i+1}题{t/tsc*100:.2f}分 {calc}="))
d = round(eval(calc)*100)/100
if g==d:
print("回答正确")
sc += t
else:
print("回答错误,答案:",d)
print(f'最终得分:{sc/tsc*100:.2f}')
如有帮助,望采纳!谢谢!