嘿,即時通訊學習蟒蛇艱難的方式事情 和我卡在練習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」值。這是你的條件,後者總是返回'真' –