为什么我的“或”语句导致任何输入退出“if”语句?

时间:2016-08-06 03:38:42

标签: python python-3.x

我对 def self.create(full_name) raise StandardError.new('Base directory for components is missing.') if base_directory_missing? raise StandardError.new('An Emerald Component must have a name.') if full_name.empty? raise StandardError.new('An Emerald Component must have a namespace.') if simple_name?(full_name) write_component(full_name) true end 很新,所以如果这是一个愚蠢的问题,我会事先道歉。我现在正在玩,并编写一个程序,要求用户解决一个谜语。请注意,我要粘贴的代码属于一个函数,但我认为分享不重要(对吗?)。当我使用此代码时,所有代码都按预期工作 -

Python

但是,当我添加“或”语句以使输入可以是“a”或“A”时,任何输入都会突然触发第一个print()语句并将我的程序移动到下一个谜语。是什么导致这种情况发生?这是破坏的代码,如果它很重要 -

    while True:
        answer = input("Option A: He stood on a block of ice until it melted. \nOption B: He floated through the water into the noose.\nWhich is the correct answer? ")
        if answer == "a":
            print("You are correct! On to the next riddle.")
            break
        else:
           print("You are incorrect. Try again.")
           continue

0 个答案:

没有答案