Python:Elif 和 Else 不工作

标签 python loops if-statement

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

相关文章:

python - 在python中创建一个按钮

python 的 sys.settrace 不会跟踪内置函数

c - Pascal 的重复...直到与 C 的重复...而

java - 我怎样才能知道 Node 或 ButtonBase 是 Button?

python - 如何用单个元素替换字符串中的多个元素?

python - Keras model.fit ValueError : Input arrays should have the same number of samples as target arrays

c - 在 C 中将数组的内容传输到另一个数组

javascript - 普通JS : Reveal only the next element at the same parent group

c++ - For循环不太有效

sql - 格式化日期中的 If/Then/Else