import random
count =0
right =0whileTrue:
a = random.randint(0,9)
b = random.randint(0,9)print('%d+%d= ?'%(a,b))
question =input('Please input your answer(q for exit):')
result = a + b
if question ==str(result):print('right!')
right +=1
count +=1elif question =='q':breakelse:print('Failed! The right answer is %s'%result)
count +=1
percent = right / count
print('测试结束,共回答%d道题,正确个数为%d,正确率为%.2f%%'%(count,right,percent *100))