|
|
发表于 2017-3-5 00:17:41
|
显示全部楼层
回帖奖励 +3 鱼币
3楼的可行,但是根据楼主的目前学习进度,一些东西超纲了,试试我的思路:
- import random
- chance = 3
- secret = random.randint(0,10)
- temp = "胃癌没有女朋友!"
- while chance >=0 :
- if chance == 0:
- temp = input("是否继续游戏?(Y/N)")
- if temp == "N" or temp =="n" :
- break
- if temp == "Y" or temp =="y":
- chance = 3
- secret = random.randint(0,10)
- temp =1
-
-
- while chance > 0:
-
- if chance == 1:
- print("你还一次机会,请小心使用!", end ="")
-
- temp = input("请你猜一个整数: ")
- if not temp.isdigit():
- print("输入错误,猜测的数值必须为整数!")
- continue
-
-
- else:
- temp = int(temp)
- #大小判断区域:
-
- if temp == secret:
- chance -= 1
- print ("猜对了,恭喜!你总共使用了",3-chance,"次机会")
- chance = 0
- continue
- if temp > secret:
- chance -= 1
- print("大了,你还有",chance,"次机会")
- if temp < secret:
- chance -= 1
- print("小了,你还有",chance,"次机会")
复制代码 |
|