1

So, in this block of code, I am having the user input a string. The user has to answer with one of the given options (which is shown in the for-loop). If the user does not respond with any option, the else statement should be used, restarting the block. However, no matter what the input for choice1 is, the if statement is always used. I am not sure what is going on with the if,elif,else statement.

print 'You enter door 1 and find a hideous internet troll.'
print "The troll says, 'LOOK AT THIS LOSER"
options = ["YOU'RE THE LOSER", "I don't care." , "YOU'RE FAT"]
for x in options:
    print "\t :> %s" % x
choice1 = raw_input("What is your response? :>")
if 'loser' or 'fat' in choice1:
    print "You are sucked into the troll's behaviour and are driven insane"
    print "After three days of insanity, you starve to death"
    dead()
elif 'care' in choice1:
    print 'The troll cannot feed off of your anger.'
    print 'The troll starves and you recover one piece of the lever from his stomach.'
    change()
    entrywayopen()
    return incomp1 == True
else:
    unknown()
    change()
    door1()
Barmar
  • 741,623
  • 53
  • 500
  • 612
nikthesnick
  • 25
  • 1
  • 3

1 Answers1

1

In the expression if 'loser' or 'fat' in choice1: only 'fat' gets checked against being in choice1. 'loser', being a non-empty string is simply interpreted as a True so you have if True or 'fat' in choice1 which always yields True. Try instead if ('loser' in choice1) or ('fat' in choice1):.

puzzlepalace
  • 660
  • 5
  • 13