Learn Python 2 | Exercise 36

Hi everyone!

I’m just posting this because I got stucked in the exercise 36. The thing is, I have to create a very simple game through different functions that need user inputs (raw_input()). I thought everything should would work but when I run the script I get error at isard == raw_input(’> ') not defined

The problematic part of the code:

elif resposta == 'pista': #or 'Pista' or 'La pista':
   print """
   Genial! Arribes al final de la pista
   i gaudeixes de les vistes però se't creua un ramat d'isards.
   Què vols fer? Espantar-los, quedar-te esperant
   o seguir caminant i deixar aparcat el cotxe?"""

  isard == raw_input('> ')
  if isard == 'espantar-los':
       print final("""
       Els Isards, més que espantats, s'han rebotat contra tu
       i t'han fet marxar caminant des d'allà cap a casa.
       Ningú creurà que el que t'ha passat.
       """)
   elif isard == "esperar":
       print """
       Els Isards estan una estona mirant-te i es queden a lloc.
       Sembla que pots seguir esperant però també seguir caminant.
       Què fas?
       """
   elif isard == "esperar":
       print final("Els isards es queden clavats.")
   elif isard == "aparcar":
       print "Amunt! Amunt!"
       Cim()
   else:
       final("Sembla ser que no saps què fer.")

Command line output:

Traceback (most recent call last):
File “exercise”, line 134, in
autopista()
File “exercise”, line 110, in autopista
Montseny() #Crida a la funció ‘Montseny()’’
File “exercise”, line 57, in Montseny
isard == raw_input(’> ')
NameError: global name ‘isard’ is not defined

I’m pretty new at programming and I don’t know what’s happening here and how to solve it. I would appreciate so much if someone can help me in this way.

Thank you so much in advance,
Ricard.

You’re issue is that you’ve used equals (==) instead of assign (=) for your variable assignment (isard)

Try:

isard = raw_input(‘> ‘)

So you are saying ‘assign whatever is captured at the prompt to a variable called isard’. Then you can compare that variable contents to all your if/else statement that are correct.

Hope that helps.

3 Likes

Oh! That helped a lot! I didn’t realize I assigned (=) the rest of the user input except this one.

Thank you so much. It was such a fast reply to my problem!