鱼C论坛

 找回密码
 立即注册
查看: 872|回复: 1

[已解决]关于while循环嵌套for循环直接终止循环问题

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

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

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

x
代码如下:
  1. import random
  2. #获取计算机的随机数
  3. computer = random.randint(0,30)
  4. active = True
  5. while active:
  6.     """定义计算器,并递减输出"""
  7.     for count in range(6,0, -1):
  8.         print("当前剩余猜测次数{0}".format(count))
  9.         guess = int(input("请输入1-30的整数 :"))
  10.         """对比guess和computer大小,如果相等,则退出游戏"""
  11.         if guess < computer:
  12.             print("Sorry,guess more than computer smaller!")
  13.         elif guess > computer:
  14.             print("Sorry,guess more than computer bigger")
  15.         else:
  16.             print("Congratulations, answer correctly.answer is {0}".format(computer))
  17.             active = False
  18.             break
  19.     """次数用尽,询问用户是否继续游戏"""
  20.     answer = input("The number of guesses has been used up,whether to continue[yes or no] :")
  21.     if answer == "yes":
  22.         continue
  23.     else:
  24.         print("Thanks for participating in the game, goodbye.")
  25.         break
复制代码


求问各位大佬,如何实现当guess = computer的时候立即终止游戏。感谢各位大佬
最佳答案
2019-6-21 23:08:45
把break改为exit()
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2019-6-21 23:08:45 | 显示全部楼层    本楼为最佳答案   
把break改为exit()
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-4-1 20:57

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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