[python]代码库
import random
print("-- -- -- -- -- -- 口算大师-- -- -- -- -- --")
while True:
coin = random.randint(1,4) #抛硬币
if coin ==1:
#加法
a = random.randint(0,10)
b = random.randint(0,10)
c = a+b
user = input(str(a)+"+"+str(b)+"=")
if str(c) == user:
print("恭喜你,答对了!")
else:
print("很遗憾,你打错了!"+"答案是"+str(c))
if coin ==2:
#减法
a = random.randint(0,10)
b = random.randint(0,10)
c = a-b
user = input(str(a)+"-"+str(b)+"=")
if str(c) == user:
print("恭喜你,答对了!")
else:
print("很遗憾,你打错了!"+"答案是"+str(c))
if coin ==3:
#乘法
a = random.randint(0,10)
b = random.randint(0,10)
c = a*b
user = input(str(a)+"*"+str(b)+"=")
if str(c) == user:
print("恭喜你,答对了!")
else:
print("很遗憾,你打错了!"+"答案是"+str(c))
if coin ==4:
#除法
a = random.randint(0,10)
b = random.randint(0,10)
c = round(a/b,2)
user = input(str(a)+"/"+str(b)+"=")
if str(c) == user:
print("恭喜你,答对了!")
else:
print("很遗憾,你打错了!"+"答案是"+str(c))