Planisphere.py ex52.py

#1

File “C:\Users\Administrator\Documents\lpthw\planisphere.py”, line 203, in
‘2’: the_end_winner,
NameError: name ‘the_end_winner’ is not defined

#2

Hi @ailsagy.

Could you please provide some more information?
What did you run when this error occour?
The code is helpful too see.

If you start to write about when and where this happens you will perhaps find it yourself.
It’s a little magic trick Zed have taught us.

#3

Any time you get that you have one of three mistakes:

  1. You spelled something wrong.
  2. You forgot to define that thing (it’s not in the file at all).
  3. You’re asking for it from the wrong place. Like it’s in one module but you try to get it from another.

Take a look at those.

#4
    good_pod = randint(1,5)
    guess = input("[pod #]> ")

    if int(guess) != good_pod:
        class the_end_loser(Room):
            def enter(self):
                print(dedent("""
                      You jump into pod '*' and hit the eject button.
                      The pod escapes out into the void of space, then
                      implodes as the hull ruptures, crushing your body into
                      jam jelly.
                      """))
                return 'death'
    else:
        class the_end_winner(Room):
            def enter(self):
                print(dedent("""
                      You jump into pod '2' and hit the eject button.
                      The pod easily slides out into space heading to the
                      planet below. As it flies to the planet, you look
                      back and see your ship implode then explode like a
                      bright star, taking out the Gothon ship at the same
                      time. You won!
                      """))
                return 'finished'

class Finished(Room):
def enter(self):
print (“You won! Good job.”)
return ‘finished’

a_map = Map(‘central_corridor’)
a_game = Engine(a_map)
a_game.play()

#5

Hi @ailsagy

I guess this is not all of the code.
There must be something in the beginning that got lost when you put it up here.
I must say this one looks a little odd:

if int(guess) != good_pod: 
    class the_end_loser(Room): 
        def enter(self): 
            print(dedent(""" You jump into pod '*' and hit the eject button.....

Creating a class inside an if statement I have never seen before.
The rest of the code perhaps explain more.

Perhaps someone else can help with this too.
I am not that skilled I can say this ever will work or not.

1 Like
A free service run by Zed A. Shaw for learncodethehardway.org.