0

hey im doing the learn python the hard way thing and im stuck at exercise 36 where you are to build something yourself. i have following code i have been going through this a lot of time trying to find my error/errors

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)

but the problem is that no matter what i type in raw input it just executes as if the first if statement is true and prints "the tiger gets angrier and eats your head off." please help me find my error

rasmus393
  • 15
  • 5
  • try `if choice== "smack it" or choice=="kick it":` – Vaulstein Jun 10 '15 at 12:01
  • 1
    Also https://stackoverflow.com/questions/20002503/why-does-a-b-or-c-or-d-always-evaluate-to-true – Cory Kramer Jun 10 '15 at 12:02
  • 1
    The first `if` statement is not working as you intended it to. It is checking whether `choice` variable is equal to the string `"smack it"` *or* whether the string value of "`kick it"` contains a `true` value. It's the latter of your condition which is always returning `true` – Anthony Forloney Jun 10 '15 at 12:02

1 Answers1

1

You should add the choice == to all of them, not only to the first one.

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)
Avión
  • 7,963
  • 11
  • 64
  • 105