from random import randint
stats = {'correct': 0, 'wrong': 0}
correct = 0
for i in range(10):
n1 = randint(1, 10)
n2 = randint(1, 10)
prod = n1 * n2
ans = input("What's %dx%d?" % (n1, n2))
if ans == prod:
print ('Your answer is correct. Well done.')
stats['correct'] += 1
else:
print (('Your answer is wrong. I am afraid the answer is %d.') % prod)
stats['wrong'] += 1
print (("\nI asked you 10 questions. You got %d of them right.") % correct)
print ("Well done!")
答案 0 :(得分:0)
从输入中收到的答案是一个字符串。
if ans == str(prod):
应该做的诀窍......