|
发表于 2017-12-29 03:57:10
|
显示全部楼层
本帖最后由 theonen 于 2017-12-29 04:05 编辑
鱼神的循环已经很完美了,直接在里面改改就可以啊。
- import random
- secret = random.randint(1,9)
- times = 3
- guess = 0 #while循环的前提
- print('猜猜我心里想什么数字:',end = "")
- while (guess != secret) and (times > 0):
- times = times-1 #次数减一
- guess = int(input())
- if guess == secret:
- print('猜中了,你真棒!')
- else:
- if guess > secret:
- print('大了大了,你还有',times,'次机会') #三合一
- else:
- print('小了小了,你还有',times,'次机会') #三合一
- if times > 0:
- print('再试试吧:',end = "")
- else:
- print("哇,真没有默契。")
- print('游戏结束')
复制代码 |
|