|
发表于 2018-2-12 10:20:45
|
显示全部楼层
本楼为最佳答案
回帖奖励 +100 鱼币
- import random
- import easygui as g
- import sys
- times = 8
- g.msgbox("嗨,欢迎进入第一个界面小游戏^_^",title = '朕的江山')
- secret = random.randint(1,100)
- msg = "不妨猜一下朕心里想的是哪个数字(1~100):"
- title = "朕的游戏"
- guess = g.integerbox(msg, title, lowerbound=1, upperbound=100)
- if guess:
- pass
- else:
- sys.exit(0)
- 参考如下代码
- while (guess != secret) and (times > 0):
- times = times - 1
- if guess == secret:
- g.msgbox("爱卿怎知道朕心里想什么?!",title = '朕的江山')
- g.msgbox("猜中了也没有奖励!",title = '朕的江山')
- break
- else:
- if guess > secret:
- g.msgbox("爱卿啊,大了大了~~~",title = '朕的江山')
- else:
- g.msgbox("爱卿啊,小了,小了~~~",title = '朕的江山')
- if times > 0:
- g.msgbox("朕再给你一次机会!",title = '朕的江山')
- guess = g.integerbox(msg, title, lowerbound=1, upperbound=100)
- if guess:
- pass
- else:
- sys.exit(0)
- else:
- g.msgbox("机会用光咯T_T",title = '朕的江山')
-
- g.msgbox("游戏结束,退朝",title = '朕的江山')
复制代码 |
|