FAQ: Errors in Python - Name Errors

This community-built FAQ covers the “Name Errors” exercise from the lesson “Errors in Python”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Analyze Financial Data with Python
Build Chatbots with Python
Build Python Web Apps with Flask

Learn Python 3

FAQs on the exercise Name Errors

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!
You can also find further discussion and get answers to your questions over in Language Help.

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head to Language Help and Tips and Resources. If you are wanting feedback or inspiration for a project, check out Projects.

Looking for motivation to keep learning? Join our wider discussions in Community

Learn more about how to use this guide.

Found a bug? Report it online, or post in Bug Reporting

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

File “script.py”, line 1, in
print(score)
NameError: name ‘score’ is not defined

I was just wondering how could the computer identify this case as a NameError instead of a SyntaxError(It can also be interpreted as ‘score’ is a string but quotation mark is missing).

What is the weird \n thing i see in the print() section?
it indicates that a new line will be printed. Which is alot easier than “”" ENTER “”"

What should go in option three other than “” ?
Please help satisfy my third eye.

How was I meant to know “yoo-hoo” was the missing option 3? What is yoo hoo? in fact what are all those options? Fresca? V8? what??

It isn’t really relevant for the lesson. They already provide the answer to the question which is A(a)/option 1, Fresca.
You are supposed to simply assign the variable ‘option3’ to any answer you want, since that’s one of the name errors you have to debug. Yoohoo, water, orange juice, it doesn’t matter. The code will use ‘A’ (option1) as the answer regardless of what beverage you assign option3 to.

Hope it makes sense.

You have prolly figured this out by now but I’m answering, nonetheless, for anyone who might be confused in the future.

Hi, forgive my ignorance, but if I remove option3 entirely from the script, would that not also fix the ‘Name Error’?

In this program there are two name errors, one is option3 variable is not defined and other one is score variable was incorrectly typed in line 19. We have two solutions here, either option3 variable can be defined or print statement in line 13 can be removed.

Hello some knows why in this program the score += 100 is in the program? I run the program without it and have no error!

Thanks☺

Jose

I agree. I knew there was an error that option3 was not defined yet. I was looking for something else in the code which would hint to what option3’s value should have been. I would have never guessed that I was just supposed to just put anything that I wanted there.

Hi, why it still gives me “#2: There’s a misspelled variable name somewhere in the program.” ?
I fixed option3 by defining it above, and scor+ in score = 100 in line 20. But it still gives me an error.

I can’t access the exercise & instructions.

What was the original code on line 20? Perhaps instead of    score = 100   , try typing    score += 100

It works! Thanks a lot :teddy_bear::ok_hand: