Python两个随机数相加
import random #引入随机数的模块
# 产生两个随机整数(0-9)
number1 = random.randint(0, 9)
number2 = random.randint(0, 9)
# 输入答案
answer = eval(input("What is " + str(number1) + " + "
+ str(number2) + "? "))
# 显示结果
print(number1, "+", number2, "=", answer,
"is", number1 + number2 == answer)
运行结果