随机出题(10以内加减乘除)
import random
Count=0
Right=0
while True:
if input() == 'exit':
break
Contole=random.randint(1, 4)
Num1=random.randint(1,10)
Num2=random.randint(1,10)
if Contole == 1:
print("%d + %d = " %(Num1,Num2),end='')
Answer=int(input())
if Answer == (Num1 + Num2):
Right += 1
print("right")
else:
print('worng')
elif Contole == 2:
print("%d - %d = " %(Num1,Num2),end='')
Answer = int(input())
if Answer == (Num1 - Num2):
Right += 1
print("right")
else:
print('worng')
elif Contole == 3:
print("%d * %d = " %(Num1,Num2),end='')
Answer = int(input())
if Answer == (Num1 * Num2):
Right += 1
print("right")
else:
print('worng')
else:
print("%d / %d = " %(Num1,Num2),end='')
Answer = int(input())
if Answer == (int(Num1 / Num2)):
Right += 1
print("right")
else:
print('worng')
Count += 1
print("总题数为:%d\n正确数量为:%d\n正确率为:%.2f" %(Count,Right,Right/Count))