A NameError is reported by the Python interpreter when it detects a variable that is unknown.

This can occur if a variable is used before it has been assigned a value or if a variable name is spelled differently than the point at which it was defined. The Python interpreter will display the line of code where the NameError was detected and indicate which name is found that was not defined.

Here’s an example of a NameError error message:

File "script.py", line 1, in <module>
NameError: name 'score' is not defined

This error is suggesting that the variable score was never defined in the program. Oops.

Some common name errors are:

  • Misspelling a variable name.
  • Forgetting to define a variable.



In script.py, another teammate Alex wrote a Who Wants to Be A Millionaire question and four options. If the answer is an uppercase or lowercase “A”, then the score goes up.

Run the program to check it out.


Oh no, there are two NameError errors!

Can you find them both?

Sign up to start coding

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?