Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/352.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_Loops_If Statement - Fatal编程技术网

Python跳转一个while循环

Python跳转一个while循环,python,loops,if-statement,Python,Loops,If Statement,我在努力避免这个循环,但这是怎么回事 while True: start = input("Ok, are you ready now?\n") if (start != "yes" and start != "no"): print ("Please enter Yes or No") else: break elif start =="no": continue 我无法编辑该问题以修复您的缩进 但我猜你

我在努力避免这个循环,但这是怎么回事

while True:
    start = input("Ok, are you ready now?\n")
    if (start != "yes" and start != "no"):
        print ("Please enter Yes or No")
        else:
            break
elif start =="no":
        continue

我无法编辑该问题以修复您的缩进 但我猜你的意思是为什么它不起作用。 对于相同的if,您不能在else之后使用elif

正确的流程是 如果 否则如果 否则

应该如此

while True:
    start = input("Ok, are you ready now?\n")
    if (start != "yes" and start != "no"):
        print ("Please enter Yes or No")
    elif start =="no":
        continue
    else:
        break

你的缩进完全错了。您的代码无效。 顺便说一下,这里有正确的缩进代码:

while True:
    start = input("Ok, are you ready now?")
    if start == "yes":
        break
    elif start == "no":
        continue
    else:
        print ("Please enter yes or no.\n")

请注意,它在Python3中工作,请修复缩进。当前代码无效。