我是初学者,请多多指教!
这次我做了一个在线数学题出题程序,下面是源码:
zzzzz=1
import random
while 1==zzzzz:
qq=0
zzz=int(input("请输入题数"))
for i in range(zzz):
q=random.randint(0,3)
if q==0:
c=random.randint(0,100)#加法随机数最小0,最大100,
h=random.randint(0,100)
a=sum([c,h])
print(c,"+",h,"=")
qc=int(input("答案"))
if qc==a:
print("t")
else:
print("f")
qq+=1
if q==1:
c=random.randint(0,100)#减法随机数最小0,最大100,避免被减数<减数。
h=random.randint(0,100)
while h>c:
h=random.randint(0,100)
a=c-h
print(c,"-",h,"=")
qb=int(input("答案"))
if qb==a:
print("t")
else:
print("f")
qq+=1
if q==2:
c=random.randint(0,10)#乘法随机数最小0,乘数1最大10,乘数2最大100。
h=random.randint(0,100)
a=c*h
print(c,"×",h,"=")
qa=int(input("答案"))
if qa==a:
print("t")
else:
print("f")
qq+=1
if q==3:
c=random.randint(1,10)#除法随机数。
h=random.randint(0,100)
a=c*h
print(a,"÷",c,"=")
qa=int(input("答案"))
if qa==h:
print("t")
else:
print("f")
qq+=1
print("你错的题数是",qq)
qqqqqqqqqqqqqqq=input("重试请按1,关闭请按2!")
if qqqqqqqqqqqqqqq=="2":
zzzzz+=1
d14d66c6-da84-4c5f-be7e-c65a28c0b3f8