2015-06-10 118 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

相關問題