题目:随机生成2个100以内的整数,随机进行加减乘除运算,共十题。输入计算结果,判断是否正确,答对一题加10分。
具体Python代码实现:
import random as rd
score = 0 # 定义一个分数变量用于统计分数
for i in range(10):
a = rd.randint(1,100)
b = rd.randint(1,100)
t = rd.randint(0,4) # 定义四个随机,用于随机 加减乘除 四种可能
result = 0 # 定义一个结果变量
if t == 0:
result = a + b
print('{}+{}=?'.format(a,b))
elif t == 1:
result = a - b
print('{}-{}=?'.format(a,b))
elif t == 2:
result = a * b
print('{}*{}=?'.format(a,b))
else:
result = a // b
print('{}//{}=?'.format(a,b))
num = int(input('结果为:')) # input()的返回值是字符串类型,需用int()转换类型
if num == result:
print('结果正确,答案是{},加十分'.format(result))
score += 10
else:
print('结果错误,答案是{}'.format(result))
print('计算完毕,你的得分是:{}'.format(score))



