鱼C论坛

 找回密码
 立即注册
查看: 2435|回复: 3

[已解决]为什么我这个程序While循环一直输出一个结果停不下来

[复制链接]
发表于 2020-11-26 22:54:31 | 显示全部楼层 |阅读模式

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

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

x
print("FrankTien")
temp = input("猜一下F内心的数字")
guess = int(temp)

if guess == 8:
        print("wWocao, You are a ChongZi")
        print("heihei,No surprise")

else:
        while guess !=8:
            if guess > 8:
                print("猜大了")

            else:
                print("嘿,小了小了")
        print("wWocao, You are a ChongZi")
        print("heihei,No surprise")

print("Game Over")
        

输入非8就一直循环 猜大了  或者 猜小了
最佳答案
2020-11-26 22:58:54


因为你的 while 循环里没有对条件进行改变

导致符合循环条件后条件循环条件一直成立而且没有 input 暂停输入而导致死循环打印

参考代码:

  1. print("FrankTien")
  2. temp = input("猜一下F内心的数字")
  3. guess = int(temp)

  4. if guess == 8:
  5.         print("wWocao, You are a ChongZi")
  6.         print("heihei,No surprise")

  7. else:
  8.     while guess !=8:
  9.         if guess > 8:
  10.             print("猜大了")

  11.         else:
  12.             print("嘿,小了小了")
  13.         temp = input("猜一下F内心的数字")
  14.         guess = int(temp)
  15.     print("wWocao, You are a ChongZi")
  16.     print("heihei,No surprise")

  17. print("Game Over")
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2020-11-26 22:58:54 | 显示全部楼层    本楼为最佳答案   


因为你的 while 循环里没有对条件进行改变

导致符合循环条件后条件循环条件一直成立而且没有 input 暂停输入而导致死循环打印

参考代码:

  1. print("FrankTien")
  2. temp = input("猜一下F内心的数字")
  3. guess = int(temp)

  4. if guess == 8:
  5.         print("wWocao, You are a ChongZi")
  6.         print("heihei,No surprise")

  7. else:
  8.     while guess !=8:
  9.         if guess > 8:
  10.             print("猜大了")

  11.         else:
  12.             print("嘿,小了小了")
  13.         temp = input("猜一下F内心的数字")
  14.         guess = int(temp)
  15.     print("wWocao, You are a ChongZi")
  16.     print("heihei,No surprise")

  17. print("Game Over")
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

 楼主| 发表于 2020-11-26 23:24:12 | 显示全部楼层
Twilight6 发表于 2020-11-26 22:58
因为你的 while 循环里没有对条件进行改变

导致符合循环条件后条件循环条件一直成立而且没有 input  ...

明白了,要重新输入给Guess赋值
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-11-26 23:24:42 | 显示全部楼层
FrankT 发表于 2020-11-26 23:24
明白了,要重新输入给Guess赋值

谢谢o
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-27 07:01

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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