import random
count = 0
right = 0
while True:
a = random.randint(0, 9)
# 作为除数
b = random.randint(1, 9)
op = [‘+‘, ‘-‘, ‘*‘, ‘//‘]
d = random.choice(op)
print(‘%d %s %d = ‘ % (a, d, b))
question = input(‘请输入您的答案: (q退出)‘)
result1 = a + b
result2 = a - b
result3 = a * b
result4 = a // b
if question == str(result1):
print(‘回答正确‘)
right += 1
count += 1
elif question == str(result2):
print(‘回答正确‘)
right += 1
count += 1
elif question == str(result3):
print(‘回答正确‘)
right += 1
count += 1
elif question == str(result4):
print(‘回答正确‘)
right += 1
count += 1
elif question == ‘q‘:
break
else:
print(‘回答错误‘)
count += 1
percent = right / count
print(‘测试结束,共回答%d道题,正确个数为%d,正确率为%.2f%%‘
% (count, right, percent * 100))
————————————————
版权声明:本文为CSDN博主「sura_1988」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_43314056/article/details/86514047
原文地址:https://www.cnblogs.com/smiorboy/p/11518667.html