|
发表于 2022-4-11 11:58:55
|
显示全部楼层
1、我现在完全明白了,首先你time =0次,这个事情,你自己看代码吧!很简单,最好你还是复习下以前的知识。
2、为啥不会出现,‘恭喜比猜对了’,主要是whilez里面的顺序,我个人认为while里‘恭喜你猜对了’必须放到最后,你还没有理解easyguiyi
- import random
- import easygui as g
- secret = random.randint(1,4)
- g.msgbox("欢迎进入第一个小游戏!!!")
- times = 3
- msg = "不妨猜下我心里想的是哪个数字(1-10之间)?"
- title = "猜数字小游戏"
- guess = g.integerbox(msg, title, lowerbound=1, upperbound=10)
- while times > 0 and guess != secret:
- times -= 1
- if times > 0:
- if guess > secret:
- guess = g.integerbox(f"数字大了,还剩下{times}次机会(1-10之间)",title,lowerbound=1,upperbound=10)
- else:
- guess = g.integerbox(f"数字小了,还剩下{times}次机会(1-10之间)",title,lowerbound=1,upperbound=10)
- else:
- break
- if guess == secret:
- g.msgbox("恭喜你猜对了")
- break
- g.msgbox("游戏结束!!!")
复制代码 |
|