我正在通过在线教程学习Python.我的问题是,当我运行脚本时,无论我输入什么响应,我得到的是if go =="kitchen"......
def go_to():
go = raw_input("Go to? ")
if go == Kitchen or breakfast:
print "You rumble down stairs and into the kitchen. Your mom has left some microwaved waffles on the table for you. Your big boy step sits by the counter."
elif go == "back to bed" or "back to sleep" or bed or sleep:
print "You hit snooze and roll over."
elif go == "bathroom" or "toilet" or "potty" or "pee" or "poop" or "take …Run Code Online (Sandbox Code Playgroud) 使用下面的代码,无论输入的第一个字母是什么,它总是被确定为元音:
original = raw_input("Please type in a word: ")
firstLetter = original[0]
print firstLetter
if firstLetter == "a" or "e" or "i" or "o" or "u":
print "vowel"
else:
print "consonant"
Run Code Online (Sandbox Code Playgroud)
实际上,在if语句中布尔值是什么并不重要......如果它是==或!=,它仍然是返回"vowel".为什么?