我正在使用 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/