如果elif和else语句跳过elif条件,则else不起作用

时间:2019-06-17 18:57:34

标签: python

这只是一些我不理解的非常简单的代码,if,elif和else语句似乎将elif语句用作else语句,而else语句不起作用。如果重要的话,我将这些语句放在while循环中。

我是python编程的新手,所以我不知道从哪里开始。我尝试注释掉elif语句,然后else语句似乎可以工作,但是将其放回原处似乎可以停用else语句。

代码如下:

print('What do you get when you cross a snowman with a vampire?')

repeat = True

response = input()


while repeat == True:

    if response == 'What?':
        print('Frostbite!')
        break
    elif response == 'Frostbite!' or 'Frostbite' or 'frostbite!' or 'frostbite':
        print('I\'m the one who\'s supposed to be telling jokes here, alright?')
        break
    else:
        print('You\'re supposed to ask \'What?\'')
        response = input()

我希望,如果输入询问例如“ Idk”,则它将跟随else语句并允许另一个输入,因为它与if或elif条件不匹配。但是,它反而回答:“我是应该在这里讲笑话的人,好吗?”应该用于elif语句。

0 个答案:

没有答案