以下是完整代码
from datetime import *
from random import *
fs = 0
now = datetime.now()
while True:
print("请选择难度\n1.简单\t2.困难\n输入'退出'或3退出")
x1 = input("我:")
if x1 == '1' or x1 == '简单':
while True:
jd = randint(0, 10)
jd_1 = randint(0, 10)
jd_2 = randint(1, 2)
if jd_2 == 1:
print("{}+{}=".format(jd, jd_1))
print("输入'退出'退出,输入'保存'保存")
jd_4 = input("我:")
jd_3 = jd + jd_1
if str(jd_3) == jd_4:
print("回答正确")
fs += 1
print("当前分数:{}".format(fs))
elif jd_4 == '退出':
print("退出简单模式")
break
elif jd_4 == '保存':
zc = open("zc.txt", "a+")
zc_1 = ["难度:简单 分数:{:2}\t保存时间:{}\n".format(fs, now)]
zc.writelines(zc_1)
for line in zc:
print(line)
zc.close()
print("保存完毕")
fs = 0
else:
print("回答错误")
fs -= 1
print("当前分数:{}".format(fs))
else:
print("{}-{}=".format(jd, jd_1))
print("输入'退出'退出,输入'保存'保存")
jd_5 = input("我:")
jd_6 = jd - jd_1
if jd_5 == str(jd_6):
print("回答正确")
fs += 1
print("当前分数:{}".format(fs))
elif jd_5 == '退出':
print("退出简单模式")
break
elif jd_5 == '保存':
zc = open("zc.txt", "a+")
zc_1 = ["难度:简单 分数:{:2}\t保存时间:{}\n".format(fs, now)]
zc.writelines(zc_1)
for line in zc:
print(line)
zc.close()
print("保存完毕")
fs = 0
else:
print("回答错误")
fs -= 1
print("当前分数:{}".format(fs))
elif x1 == '2' or x1 == '困难':
while True:
kn = randint(10, 20)
kn_1 = randint(10, 20)
kn_2 = randint(1, 2)
if kn_2 == 1:
print("{}+{}=".format(kn, kn_1))
print("输入'999'退出,输入'333'保存")
kn_3 = int(input("我:"))
if kn_3 == kn + kn_1:
print("回答正确")
fs += 1
print("当前分数:{}".format(fs))
elif kn_3 == 999:
print("退出困难模式")
break
elif kn_3 == 333:
zc = open("zc.txt", "a+")
zc.write("难度:困难 分数:{:2}\t保存时间:{}\n".format(fs, now))
for line in zc:
print(line)
zc.close()
print("保存完毕")
fs = 0
else:
print("回答错误")
fs -= 1
print("当前分数:{}".format(fs))
else:
print("{}-{}=".format(kn, kn_1))
print("输入'999'退出,输入'333'保存")
kn_5 = int(input("我:"))
kn_6 = kn - kn_1
if kn_5 == kn_6:
print("回答正确")
fs += 1
print("当前分数:{}".format(fs))
elif kn_5 == 999:
print("退出困难模式")
break
elif kn_5 == 333:
zc = open("zc.txt", "a+")
zc.write("难度:困难 分数:{:2}\t保存时间:{}\n".format(fs, now))
for line in zc:
print(line)
zc.close()
print("保存完毕")
fs = 0
else:
print("回答错误")
fs -= 1
print("当前分数:{}".format(fs))
elif x1 == '退出' or x1 == '3':
print("退出")
break
else:
print("输入错误")
以下是速算的另一个版本,其具有图形界面及详细解释