|

楼主 |
发表于 2022-5-3 21:23:29
|
显示全部楼层
- #p4_4.py
- import easygui as eg
- import random as rdm
- try:
- eg.msgbox(msg = '欢迎进入猜数字小游戏!' , title = '猜数字小游戏' , ok_button = '继续')
- 答案 = rdm.randint(1,1000)
- 回答 = eg.integerbox(msg = '猜一猜作者心里想的是什么数字(1-1000):' , title = '猜数字小游戏' , lowerbound = 1 , upperbound = 1000)
- 次数 = 1
- while 回答!= 答案 and 次数 <= 20:
- if 回答 == None:
- eg.msgbox(msg = '输入不能为空!' , title = '请重来!' , ok_button = '重来')
- continue
- if 回答 > 答案:
- 回答 = eg.integerbox(msg = '嘿,大啦大啦!请重新输入:' , title = '很遗憾,猜错啦!' , lowerbound = 1 , upperbound = 1000)
- 次数 += 1
- if 回答 < 答案:
- 回答 = eg.integerbox(msg = '嘿,小啦小啦!请重新输入:' , title = '很遗憾,猜错啦!' , lowerbound = 1 , upperbound = 1000)
- 次数 += 1
- if 回答 == 答案:
- eg.msgbox(msg = '回答正确!' , title = '恭喜您,猜中了!' , ok_button = '确定')
- except ValueError as cut:
- eg.msgbox(msg = ('类型出错啦T_T\n错误原因是:' + cut) , title = '错误' , ok_button = '确定')
复制代码 为啥不能?运行也没有问题呀~ |
|