|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#p3_85.py
import easygui as eg
import random as rdm
try:
eg.msgbox(msg = '欢迎进入猜数字小游戏!' , title = '猜数字小游戏' , ok_button = '继续')
答案 = rdm.randint(1,100)
回答 = eg.integerbox(msg = '猜一猜作者心里想的是什么数字(1-100):' , title = '猜数字小游戏' , lowerbound = 1 , upperbound = 100)
while 回答!= 答案:
if 回答 == 答案:
eg.msgbox(msg = '回答正确!' , title = '恭喜您,猜中了!' , ok_button = '确定')
break
else:
if 回答 > 答案:
eg.integerbox(msg = '嘿,大啦大啦!请重新输入:' , title = '很遗憾,猜错啦!' , lowerbound = 1 , upperbound = 100)
if 回答 < 答案:
eg.integerbox(msg = '嘿,小啦小啦!请重新输入:' , title = '很遗憾,猜错啦!' , lowerbound = 1 , upperbound = 100)
eg.msgbox(msg = '游戏结束!' , title = '结束' , ok_button = '确定')
except ValueError as cut:
eg.msgbox(msg = ('类型出错啦T_T\n错误原因是:' + cut) , title = '错误' , ok_button = '确定')
为啥要不一直说大了,要不就是小了?
重新猜之后得赋值,不然回答一直不变#p3_85.py
import easygui as eg
import random as rdm
try:
eg.msgbox(msg = '欢迎进入猜数字小游戏!' , title = '猜数字小游戏' , ok_button = '继续')
答案 = rdm.randint(1,100)
回答 = eg.integerbox(msg = '猜一猜作者心里想的是什么数字(1-100):' , title = '猜数字小游戏' , lowerbound = 1 , upperbound = 100)
while 回答!= 答案:
if 回答 == 答案:
eg.msgbox(msg = '回答正确!' , title = '恭喜您,猜中了!' , ok_button = '确定')
break
else:
if 回答 > 答案:
回答 = eg.integerbox(msg = '嘿,大啦大啦!请重新输入:' , title = '很遗憾,猜错啦!' , lowerbound = 1 , upperbound = 100) # 注意这里
if 回答 < 答案:
回答 = eg.integerbox(msg = '嘿,小啦小啦!请重新输入:' , title = '很遗憾,猜错啦!' , lowerbound = 1 , upperbound = 100) # 注意这里
eg.msgbox(msg = '游戏结束!' , title = '结束' , ok_button = '确定')
except ValueError as cut:
eg.msgbox(msg = ('类型出错啦T_T\n错误原因是:' + cut) , title = '错误' , ok_button = '确定')
|
|