|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import easygui as g
import random
secret = random.randint(1,10)
temp = g.integerbox(msg='不妨猜一下小甲鱼现在心里想的是哪个数字:', title='数字小游戏', default='', lowerbound=1, upperbound=10)
# guess = int(temp)
while guess != secret:
temp = g.integerbox(msg='哎呀,猜错了,请重新输入吧:', title='数字小游戏', default='', lowerbound=1, upperbound=10)
# guess = int(temp)
if guess == secret:
g.msgbox("我草,你是小甲鱼心里的蛔虫吗?!")
g.msgbox("哼,猜中了也没有奖励!")
else:
if guess > secret:
g.msgbox("哥,大了大了~~~")
else:
g.msgbox("嘿,小了,小了~~~")
g.msgbox("游戏结束,不玩啦^_^")
easygui课后题第一题,用integerbox会报错:
Traceback (most recent call last):
File "D:/backup/python/fishc/第三次学习的练习代码/035-easygui实现猜数字小游戏.py", line 6, in <module>
temp = g.integerbox(msg='不妨猜一下小甲鱼现在心里想的是哪个数字:', title='数字小游戏', default='', lowerbound=1, upperbound=10)
File "C:\Users\DDD\AppData\Local\Programs\Python\Python36\lib\easygui\boxes\derived_boxes.py", line 288, in integerbox
default = convert_to_type(default, int, "default")
File "C:\Users\DDD\AppData\Local\Programs\Python\Python36\lib\easygui\boxes\derived_boxes.py", line 241, in convert_to_type
ret_value = new_type(input_value)
ValueError: invalid literal for int() with base 10: ''
这一句
- temp = g.integerbox(msg='不妨猜一下小甲鱼现在心里想的是哪个数字:', title='数字小游戏', default='', lowerbound=1, upperbound=10)
复制代码
选项:default='' 出了问题,似乎不允许使用空串。
- import easygui as g
- import random
- secret , guess = random . randint(1,10) , 0
- while True:
- guess = g . integerbox(msg = '不妨猜一下小甲鱼现在心里想的是哪个数字:' , title = '数字小游戏' , default = str(guess) , lowerbound = 1 , upperbound = 10)
- if guess == secret:
- g . msgbox("我草,你是小甲鱼心里的蛔虫吗?!")
- g . msgbox("哼,猜中了也没有奖励!")
- break
- else:
- if guess > secret:
- g . msgbox("哥,大了大了~~~")
- else:
- g . msgbox("嘿,小了,小了~~~")
- g.msgbox("游戏结束,不玩啦^_^")
复制代码
|
|