import random
max_n = 100
i = 0
while True:
i += 1
# 随机运算,0+,1-
op = random.randint(0, 1)
# +
if op == 0:
x1 = random.randint(0, max_n)
x2 = random.randint(0, max_n - x1)
result = x1 + x2
qst = str(x1) + "+" + str(x2) + "="
question = [qst, result]
# -
elif op == 1:
x1 = random.randint(0, max_n)
x2 = random.randint(0, x1)
result = x1 - x2
qst = str(x1) + "-" + str(x2) + "="
question = [qst, result]
x = input("第{:>2d}题:{}".format(i + 1, question[0]))
if int(x) == int(question[1]):
print("回答正确!")
else:
print("回答错误!{}{}".format(question[0], question[1]))