gpt4 book ai didi

Python:Elif 和 Else 不工作

转载 作者:行者123 更新时间:2023-12-01 03:32:30 25 4
gpt4 key购买 nike

我正在使用 Python 为终端构建一个交互式时间表,但在我的代码末尾,我有 if、elif 和 else 语句,无论我给出什么用户输入,它都会继续传递 if 语句。任何解决方案将不胜感激,并感谢您的时间:)

while True:
TimeTable()
print "\nDo you wish to go again? "
answer = raw_input()
if answer == "Yes" or "yes":
print " "
continue
elif answer == "No" or "no":
print "Ok then"
break
else:
print "Ok then"
break

最佳答案

answer == "Yes" or "yes"

# is the same as
(answer == "Yes") or "yes"

且始终为 True。您可以这样解决您的问题:

answer in ["Yes", "yes"]

关于Python:Elif 和 Else 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40716932/

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