Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: 'in <string>' requires string as left operand not list

Tags:

python

I am working through Exercise 35 of Learn Python The Hard Way (LPTHW).

http://learnpythonthehardway.org/book/ex35.html

I am struggling with one of the study drills of this exercise. Specifically "Add more to the game".

Here is the code that is returning the error:

def bear_room(): # A new encounter
    print "There is a bear here."
    print "The bear has a bunch of honey."
    print "The fat bear is in front of another door."
    print "How are you going to move the bear?"

    bear_moved = False 

while True: 
    next = str(raw_input("> "))

    if ["honey", "take"] in next: 
        dead("The bear peers at you for a moment, sizing you up, then claws your face off.")
    elif ["taunt", "lure", "yell", "scream", "shout"] in next:
        print "the bear has moved from the door. You can go through it now."
        bear_moved = True
    elif ["taunt", "lure", "yell", "scream", "shout"] in next and bear_moved: 
        dead("The bear gets pissed off and chews your leg off.")
    elif ["open", "door", "next", "through", "onward"] in next and bear_moved:
        gold_room()
    else:
        print "I got not idea what that means."
like image 563
Harrison Boles Avatar asked Feb 14 '23 21:02

Harrison Boles


1 Answers

It's next in ["taunt", "lure", "yell", "scream", "shout"]

not

["taunt", "lure", "yell", "scream", "shout"] in next

You have the test backwards.

like image 123
SpliFF Avatar answered Mar 02 '23 21:03

SpliFF