Python
import randomimport 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.这样的情况 您输入的值小于10的下限
那就是没有输入规定范围内的数字才会这样
integerbox() :为用户提供一个简单的输入框,用户只能输入范围内(lowerbound 参数设置最小值,upperbound 参数设置最大值)的整型数值,否则会要求用户重新输入。
这个就是 integerbox() 组件的功能呀,当你输入不在你设置的 g.integerbox(msg,title,1,10) 范围内就会显示这个的提示的
The value that you entered is less than the lower bound of 10. 的意思是 :
您输入的值小于10的下界.
Twilight6 发表于 2020-7-14 16:49
这个就是 integerbox() 组件的功能呀,当你输入不在你设置的 g.integerbox(msg,title,1,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)
页:
[1]