Python "Else" 语句总是 returns 真

Python "Else" statement always returns True

My Code

print("Hello World")
print("How're you?")
mood = input()
print("I'm " + mood + " too")
print("What's your name?")
name = input()
print(name + ". I really like that name!")
food = input("I really like pizza. Do you? Y/N ")
if food == 'y' or 'Y':
    print("Wow! " + name + ", you and I have a really similar taste in food, don't we? So what else do you like?")
elif food == 'n' or 'N':
    print("Oh, that's a shame. I was gonna treat us to a cheeky Papa Johns!")
else:
    print("Oh! Okay. Then what else do you like?")
other = input()
if other == 'liquorice' or 'Liquorice' or 'Brussels Sprouts' or 'brussels sprouts':
    print("Blegh! " + name + ", I respect you and all... but gross!")

Output

我试图让程序在输入 Y 或 y(代表是)以外的内容时使用 ELIF 和 ELSE 输出。我需要做什么来修复这个错误?

当您使用

if food =='y' or 'Y':

python 将一直 return 为真,您可以测试一下:

if 'false':
    print('true')

要使其正常工作,请将 food =='y' or 'Y' 替换为 food =='y' or food=='Y' 或按照@Peter Wood 的建议,使用 food

的 lower/upper