嘿,即时通讯学习蟒蛇艰难的方式事情 和我卡在练习36,你要自己建立的东西。 我有以下代码 我已经通过这个去了很多时间试图找到我的错误/错误如果声明不工作,因为我期望他们在python
choice = raw_input("> ")
if choice == "smack it" or "kick it":
print "the tiger gets angrier and eats your head of"
exit(0)
elif choice == "offer it the beef" or "offer it beef" or "offer it the beef in my pocket":
print "the tiger enjoys the treat"
print "and lets you go to the next room"
bear_room
else:
print "the tiger smels the beef you have in you pocket and eats you"
exit(0)
但问题是,无论我在原始输入类型,它只是执行,就好像第一如果陈述是真实的并且印刷“老虎更加愤怒并且吃掉您的头”。 请帮我看看我的错误
试试'如果选择== “嫌它” 或选择== “踢”:' – Vaulstein
另外https://stackoverflow.com/questions/20002503/why-does-ab-or-c- or-d-always-evaluate-to-true – CoryKramer
第一个'if'语句不能按照您的预期工作。它检查'choice'变量是否等于字符串'“smack it”*或“kick it”的字符串值是否包含“true”值。这是你的条件,后者总是返回'真' –