|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import random
import easygui as g
g.msgbox('嗨,欢迎进入小游戏')
secret = random.randint(1,10)
msg = '不妨猜一下我心里的数字(1~10)'
title = '数字小游戏:'
guess = g.integerbox(msg,title,lowerbound=1,upperbound=10)
while True:
if guess == secret:
g.msgbox('卧槽,你是我的蛔虫')
break
else:
if guess >secret:
g.msgbox('大了大了')
else :
g.msgbox('小了小了')
guess = g.integerbox(msg,title,1,10)
g.msgbox('游戏结束')
为什么我运行起来会有The value that you entered is less than the lower bound of 10.这样的情况
本帖最后由 sunrise085 于 2020-7-14 16:56 编辑
倒数第二行写的不对
- guess = g.integerbox(msg,title,1,10)
复制代码
这句的后两个参数你没有写关键字,所以会以默认顺序给对应参数赋值
- ntegerbox(msg='', title=' ', default=None, lowerbound=0, upperbound=99, image=None, root=None)
复制代码
所以,1赋值给了参数default,10赋值给了参数lowerbound
所以运行的时候,第二次出现输入框的时候,框内会有一个默认值1,而且此时下边界为10,你输入10以下的就会报出提示了
应该改为和上面那一行输入框一样。
- guess = g.integerbox(msg,title,lowerbound=1,upperbound=10)
复制代码
|
|