2015-06-10 134 views
0

嘿,即时通讯学习蟒蛇艰难的方式事情 和我卡在练习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) 

但问题是,无论我在原始输入类型,它只是执行,就好像第一如果陈述是真实的并且印刷“老虎更加愤怒并且吃掉您的头”。 请帮我看看我的错误

+0

试试'如果选择== “嫌它” 或选择== “踢”:' – Vaulstein

+1

另外https://stackoverflow.com/questions/20002503/why-does-ab-or-c- or-d-always-evaluate-to-true – CoryKramer

+1

第一个'if'语句不能按照您的预期工作。它检查'choice'变量是否等于字符串'“smack it”*或​​“kick it”的字符串值是否包含“true”值。这是你的条件,后者总是返回'真' –

回答

1

你应该把choice ==加到它们全部,不仅仅是第一个。

choice = raw_input("> ") 
if choice == "smack it" or choice == "kick it": 
    print "the tiger gets angrier and eats your head of" 
    exit(0) 
elif choice == "offer it the beef" or choice == "offer it beef" or choice == "offer it the beef in my pocket": 
    print "the tiger enjoys the treat" 
    print "and lets you go to the next room" 

else: 
    print "the tiger smels the beef you have in you pocket and eats you" 
    exit(0) 
+0

因为我无法upvote你还没有足够的代表我只是会说非常感谢你我不知道这 – rasmus393

+0

如果我没有错,我认为你需要10分钟接受一个答案。所以你接受答案,如果这是你正在寻找的。 –

+0

好吧,我现在可以让你走了 – rasmus393

相关问题