gpt4 book ai didi

Python 跳转 while 循环

转载 作者:太空宇宙 更新时间:2023-11-03 17:14:22 27 4
gpt4 key购买 nike

我正在尝试避免这个 while 循环出了什么问题

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?")
if start == "yes":
break
elif start == "no":
continue
else:
print ("Please enter yes or no.\n")

请注意,它适用于Python3

关于Python 跳转 while 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33778063/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com