我正在通过在线教程学习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 a sh*t" or "take a dump" or "drop a load":
print "You make a stop at the head first."
go_to()
else:
print "That is not a command I understand."
go_to()
go_to()
Run Code Online (Sandbox Code Playgroud)
正如评论中提到的,您的使用在or这里是不正确的.这个:
go == "kitchen" or "breakfast"
Run Code Online (Sandbox Code Playgroud)
相当于:
(go == "kitchen") or "breakfast"
Run Code Online (Sandbox Code Playgroud)
该or运营商投下两个操作数到布尔值,它给你的:
(something) or true
Run Code Online (Sandbox Code Playgroud)
这总是减少到true,所以你总是输入if语句