'Getting There' lesson - don't understand error message


I am requesting help as to why this error is generated on the below code written in response to a lesson:

Error Message:
Traceback (most recent call last):
File “python”, line 4, in
File “”, line 1, in
NameError: name ‘Tampa’ is not defined

What does this mean? Why would Tampa need to be defined - it’s just one possible user input.

city = input("Please enter your vacation destination: ")

def plane_ride_cost(city):
if city == ‘Charlotte’:
return 183
elif city == ‘Tampa’:
return 220
elif city == ‘Pittsburgh’:
return 222
elif city == ‘Los Angeles’:
return 475
return “Sorry, you cannot travel there.”

print plane_ride_cost(city)


Non-standard quotes are not recognized by the parser. Use ' or " on strings.


This statement is likely to cause problems in Python 2, which is the version currently taught by Codecademy …

city = input("Please enter your vacation destination: ")

With Python 2, use raw_input instead of input. In Python 2, the input function attempts to parse and evaluate the input as a Python expression. For example, if the user enters Charlotte without quotes in response to the prompt, the Python interpreter attempts to evaluate Charlotte as a variable, and in this case, discovers that it is not defined, and issues a NameError.

See the following documentation …

Be aware that in Python 3, the raw_input function has been removed and replaced by input function, which in Python 3 operates as the raw_input does in Python 2.


It should be noted that this exercise does not ask for nor expect there to be any user input. The learner is advised to stick with the lesson material and do not deviate from the instructions. Once the track is completed, then would be the time for experimentation.


2.7, as suspected. I had hoped they would upgrade to 3 on the migration, just as they have begun integrating ES6 topics, but it looks to be not the case, at least not yet.


Hopefully, they will upgrade soon.

From PEP 373 – Python 2.7 Release Schedule:

The End Of Life date (EOL, sunset date) for Python 2.7 has been moved five years into the future, to 2020.

Based on that expectation, it would be a good idea to favor Python 3 over Python 2, whenever that is practical, well in advance of the year 2020.

What could be better than 2020 foresight? :wink:

Screen capture on September 14, 2017 from Python 2.7 will retire in….


Good one! Thanks for the info.


Still, there is enough time to learn Python 2 and be able to recognize code that needs upgrading in the field. That is what maintenance is all about, after all. Can’t fix what you can’t spot.


Yes, agreed. It is certainly worthwhile for Codecademy users to complete the exercises in the existing Python track. After all, learning Python 2 constitutes learning much about Python 3, since in most respects, the two versions are the same.

Yes, we need programmers to learn both versions, so that they become adept at upgrading Python 2 code to Python 3 code.

It will be interesting to see a new set of Python 3 exercises on Codecademy in the future. Perhaps it can include one module focused on upgrading code from Python 2 to Python 3, since there is much work to be done in that regard.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.