python⾃动⽣成加减乘除计算最简单代码import random
count = 0
right = 0
while True:
a = random.randint(1, 11)
b = random.randint(1, 11)random python
dict = [["%d+%d=" % (a, b), a + b], ["%d-%d=" % (a, b), a - b], ["%d*%d=" % (a, b), a * b],
["%d/%d=" % (a, b), a // b]]
i = random.randint(0, 3)
num = input("%s? input your answer[q exit]" % (dict[i][0]))
if num == "q":
break
elif int(num) == dict[i][1]:
count += 1
right += 1
print("right")
else:
count += 1
print("wrong")
if count != 0:
print("total is %d\nright nums is %d\n right rate is %d\n" % (count, right, right / count))
else:
print("Loser are you!")

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。