|
|
发表于 2018-6-9 16:09:04
|
显示全部楼层
hi 请lz参考
- import random as r
- secret = r.randint(1,10)
- print('不妨猜一下小甲鱼现在心里想的是哪个数字:', end = ' ')
- times = 3
- [color=Red]while times:
- temp = input() #不太理解 | 此处接收用户的输入
- guess = int(temp )#不太理解 | 因为通过input()函数输入的均是字符型,因此需要通过 int()函数转换为整型
- times -= 1[/color]
-
- if guess == secret:
- print('哎呀,你是小甲鱼肚里的蛔虫吗?')
- print('哼~猜中了也没有奖励!')
- break #猜中后跳出循环,break是后续“分支与循环”中的内容
- else:
- if guess > secret:
- print('哥,大了大了~~~')
- else:
- print('嘿,小了小了~~~')
-
- [color=Red] if times:
- print('你还有%d次机会,请重新输入:' % times, end = ' ') #不理解 if times 是有次数的话 打印剩余机会 反之 打印已用完 结束游戏 '你还有%d次机会,请重新输入:' % times, end = 这句不太理解[/color] | 打印剩余机会并提示用户重新输入;print()函数默认以换行结尾,end='' 表示已''结尾、即:不换行
- else:
- print('机会用光咯,非常遗憾!')
- print('游戏结束,不玩啦^_^')
复制代码 |
|