鱼C论坛

 找回密码
 立即注册
查看: 2406|回复: 5

[已解决]这种改进如何改进呢~

[复制链接]
发表于 2019-6-2 19:28:00 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
print("欢迎进行python文字的第三次文字游戏改进测试")
temp = input("please fall a number in the bank")
guess = int(temp)
while guess != 8:
    chance = 3
    chance = chance -1
    if guess >8:
        print("bigger than answer")
    else :
        print("smaller than answer")

    temp = input("please try again ")
    guess =int(temp)
print("you are right")
input("The game is over!")
while chance == 0:
    print("sorry, you have 3 times to answer this question")
input("the game is over")
最佳答案
2019-6-2 19:55:21
  1. print("欢迎进行python文字的第三次文字游戏改进测试")
  2. temp = input("please fall a number in the bank")
  3. guess = int(temp)
  4. chance = 2
  5. while chance != 0:
  6.    
  7.    
  8.     if guess >8:
  9.         print("bigger than answer")
  10.     elif guess <8:
  11.         print("smaller than answer")
  12.     else:
  13.         break
  14.     temp = input("please try again ")
  15.     guess =int(temp)
  16.     chance = chance -1
  17. if guess != 8:
  18.     print("sorry, you have 3 times to answer this question")
  19. else:
  20.     print("you are right")
  21. print("The game is over!")
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2019-6-2 19:28:36 | 显示全部楼层
英语有点烂,不要介意。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-6-2 19:29:29 | 显示全部楼层
我想让chance = 0的时候,就结束这个游戏,
但是 好像while 一直重复的时候,会反复运行chance = 3
这就会导致一直退不出去。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-6-2 19:55:21 | 显示全部楼层    本楼为最佳答案   
  1. print("欢迎进行python文字的第三次文字游戏改进测试")
  2. temp = input("please fall a number in the bank")
  3. guess = int(temp)
  4. chance = 2
  5. while chance != 0:
  6.    
  7.    
  8.     if guess >8:
  9.         print("bigger than answer")
  10.     elif guess <8:
  11.         print("smaller than answer")
  12.     else:
  13.         break
  14.     temp = input("please try again ")
  15.     guess =int(temp)
  16.     chance = chance -1
  17. if guess != 8:
  18.     print("sorry, you have 3 times to answer this question")
  19. else:
  20.     print("you are right")
  21. print("The game is over!")
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

 楼主| 发表于 2019-6-3 08:32:59 | 显示全部楼层

谢谢大佬,原来要先做一个while的机会语句。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-6-5 21:28:44 | 显示全部楼层
  1. import random
  2. #获取1-30的随机数quession
  3. quession = random.randint(1,30)
  4. #定义while循环标记
  5. active = True
  6. while active:
  7.     #定义次数计数器
  8.     for i in range(6,0, -1):
  9.         #获取用户输入
  10.         answer = int(input("请输入1-30的整数回答问题:"))
  11.         print('目前还有%d次猜测机会!' % i)
  12.         if answer > quession:
  13.             print("猜大了,请努力")
  14.         elif answer < quession:
  15.             print("猜小了,请努力")
  16.         elif answer == quession:
  17.             print("真棒,回答正确!正确答案为%d ." % quession)
  18.             #如果用户回答正确,重置while标记退出循环
  19.             active = False
  20.             break
  21.     #猜测次数用完后,判断用户是否想继续游戏        
  22.     else:
  23.         count = input("目前已经没有回答机会,请问是否放弃游戏[y/n]:")
  24.         if count == "n":
  25.             continue
  26.         else:
  27.             break
  28.             
  29. 这是我的猜数代码,有兴趣可以参考下
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-5-16 18:51

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表