Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么';我的while循环不能停止吗?_Python_While Loop - Fatal编程技术网

Python 为什么';我的while循环不能停止吗?

Python 为什么';我的while循环不能停止吗?,python,while-loop,Python,While Loop,我一直在读其他的帖子,但我想不出来。无论我在这个重复的结尾输入什么,它总是重复循环。我试过虽然(重复!=“退出”或重复!=“退出”或重复!=“b”或重复!=“b”或重复!=“否”或重复!=“否”):但仍然不起作用。我不知道还能尝试什么。这个while循环有什么问题 repeat = "d" print "Please answer questions using the choices (A, B, C, etc.)" time.sleep(2.1738) whi

我一直在读其他的帖子,但我想不出来。无论我在这个重复的结尾输入什么,它总是重复循环。我试过
虽然(重复!=“退出”或重复!=“退出”或重复!=“b”或重复!=“b”或重复!=“否”或重复!=“否”):
但仍然不起作用。我不知道还能尝试什么。这个while循环有什么问题

    repeat = "d"
    print "Please answer questions using the choices (A, B, C, etc.)"
    time.sleep(2.1738)
    while repeat != "Quit" or repeat != "quit" or repeat != "b" or repeat != "B" or repeat != "no" or repeat != "No":
        print "A) Round Edges"
        print "B) Straight Edges"
        Edges1 = raw_input("Does the shape have round edges or straight edges?: ")
        if Edges1 == "a" or Edges1 == "A" or Edges1 == "Round Edges" or Edges1 == "round edges":
            print "A) Circle"
            print "B) Semi-Circle"
            Circle = raw_input("Is it a circle or semi-circle?: ")
            if Circle == "A" or Circle == "a" or Circle == "Circle" or Circle == "circle":
                radius_C = input("What is the radius (1/2 of the Diameter)?: ")
                Area_C = math.pi * radius_C ** 2.0
                Circum_C = 2.0 * math.pi * radius_C
                Diameter_C = 2.0 * radius_C
                print "The radius is " + str(radius_C) + ". "
                time.sleep(.5)
                print "The diameter is " + str(Diameter_C) + ". "
                time.sleep(.5)
                print "The circumference is " + str(round(Circum_C, 2)) + ". "
                time.sleep(.5)
                print "The area is " + str(round(Area_C, 2)) + ". "
                time.sleep(5)
            elif Circle == "B" or Circle == "b" or Circle == "Semi-Circle" or Circle == "semi-circle":
                radius_S = input("What is the radius (1/2 of the Diameter)?: ")
                Area_S = math.pi * radius_S ** 2.0 * .5
                Diameter_S = 2 * radius_S
                Per_S = ((math.pi * 2 * radius_S) / 2) + Diameter_S
                print "The radius is " + str(radius_S) + ". "
                time.sleep(.5)
                print "The diameter is " + str(Diameter_S) + ". "
                time.sleep(.5)
                print "The perimeter is " + str(round(Per_S, 2)) + ". "
                time.sleep(.5)
                print "The area is " + str(round(Area_S, 2)) + ". "
                time.sleep(5)
            else:
                print "Incorrect input."
        elif Edges1 == "b" or Edges1 == "B" or Edges1 == "Straight Edges" or Edges1== "straight edges":
            sides = input("How many sides does the shape have?: ")
            sideL = input("What is the length of 1 side?: ")
            Area = round(Area_R(sides, sideL), 4)
            Perim = round(Perm_R(sides, sideL), 4)
            print "The area of this figure is: " + str(Area)
            print "The perimeter of the figure is: " + str(Perim)
        else:
            print "Incorrect input."


        time.sleep(4)
        print" "
        print" "
        print "A) yes"
        print "B) No"
        repeat = raw_input("Want to try another?: ")
        time.sleep(1)
main()

将or替换为and,如下所示:

while repeat != "Quit" and repeat != "quit" and repeat != "b" and repeat != "B" and repeat != "no" and repeat != "No":
它总是不等于这些东西中的至少一个。它不可能同时等于两件事。下面是另一个较短的示例(请尝试我上面的建议)


P>嗯,让我们来看一下这个条件:

while repeat != "Quit" or repeat != "quit"
想想看。无论
repeat
的值是多少,这总是正确的<代码>重复将始终不同于
“退出”
“退出”
。如果是一个,就不会是另一个

您需要它与“退出”和“退出”不同。试试这个:

while repeat != "Quit" and repeat != "quit" ...
或者,更紧凑:

while repeat.lower() not in ["quit", "b"]

我想你的意思是
而不是
…哇,这么简单的修复方法:/也许,我发现它更容易,因为我没有阅读循环中的所有代码——我假设问题会出现在第一行或最后一行。下一次,当您找不到问题时,请找到有问题的最小代码段,并攻击它:)
while repeat.lower() not in ["quit", "b"]