import random def number1(option): i=random.randint(1,10) return i def number2(option): j = random.randint(1, 10) return j def options(i,j,option): if option=='+': return i+j if option=='-': return i-j if option=='*': return i*j if option=='/': return i/j option = input("请选择加减乘除法:+ or - or * or /") yes=0 all=0 i=number1(option) j=number2(option) for k in range(1,100): print("题目:%d %s %d=?"%(i,option,j)) n=float(input('答案')) answer=options(i,j,option) if n==answer: print("答对了") yes+=1 else: print("答错了") all+=1 out=input('想退出请按q') if out=='q' : break else: continue scale=(yes/all)*100 print("本次答对%d个"%yes) print("正确率%.f%%"%scale)
python 随机数四则运算
最新推荐文章于 2024-08-16 00:28:12 发布