马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
马上回老家啦!于是给亲戚小孩写个“帮助”练习运算的东西(翻译:我看不得别人轻松 )
bug比较多(例如:减法和除法会出小数)import easygui as eg
import random as rd
yunsuan = eg.buttonbox('你想练习哪种运算', choices=['加法', '减法', '乘法', '除法'])
if yunsuan == '加法':
number = int(eg.enterbox('你希望加数的范围是从零到几'))
while True:
num1 = rd.randint(0, number + 1)
num2 = rd.randint(0, number + 1)
reply = eg.enterbox('答案是几?', f'{num1}+{num2}是多少')
if int(reply) == num1 + num2:
eg.msgbox('答对了!')
else:
eg.msgbox('答错啦!再接再厉!')
elif yunsuan == '减法':
number = int(eg.enterbox('你希望减数与被减数的范围是从零到几'))
while True:
num1 = rd.randint(0, number + 1)
num2 = rd.randint(0, number + 1)
reply = eg.enterbox('答案是几?', f'{num1}-{num2}是多少')
if int(reply) == num1 - num2:
eg.msgbox('答对了!')
else:
eg.msgbox('答错啦!再接再厉!')
elif yunsuan == '乘法':
number = int(eg.enterbox('你希望乘数的范围是从零到几'))
while True:
num1 = rd.randint(0, number + 1)
num2 = rd.randint(0, number + 1)
reply = eg.enterbox('答案是几?', f'{num1}×{num2}是多少')
if int(reply) == num1 * num2:
eg.msgbox('答对了!')
else:
eg.msgbox('答错啦!再接再厉!')
elif yunsuan == '除法':
number = int(eg.enterbox('你希望除数与被除数的范围是从零到几'))
while True:
num1 = rd.randint(0, number + 1)
num2 = rd.randint(0, number + 1)
reply = eg.enterbox('答案是几?', f'{num1}÷{num2}是多少')
if int(reply) == num1 / num2:
eg.msgbox('答对了!')
else:
eg.msgbox('答错啦!再接再厉!')
写的不好,不求评分,但求评论!
不知道为什么今天的帖子老发布出去,这是第三遍尝试了】
|