← ACARA Digital Technologies Years 7–8

NameError: using a name Python does not know

An error Python raises when code uses a variable or function name it does not know, often from a typo, wrong capitals, missing quotes or using a name before it is assigned.

Understanding NameError: using a name Python does not know in ACARA Digital Technologies Years 7–8

What it does: The variable was made as name in lowercase, so asking for Name with a capital N causes a NameError. Assigning total on the first line means Python knows the name when print() uses it on the next line, so there is no NameError. Python is case-sensitive. age and Age are different names, so using the wrong capitals can cause a NameError. Text needs quotes. Without them Python looks for a variable called Hello and cannot find it.

Common mistakes: Ava is text, so it needs quotes. Without them Python looks for a variable called Ava and raises a NameError. It should be name = "Ava". scor is a misspelling of score. Python does not know a name called scor, so it raises a NameError. It should be score = score + 5.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 482–519) and word search (Modules 420–519).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
Which line causes a NameError? score = 10 print(scor)
score = 10print(scor)
Matches
print(points) points = 10
↓
The variable points is used on line 1 before it is assigned on line 2, so Python raises a NameError. Assign it first, then print it.
Applying
Meanings
Term
NameError
Meaning
An error Python raises when code uses a variable or function name it does not know, often from a typo, wrong capitals, missing quotes or using a name before it is assigned.
Practice
score = 10
Testing
Gaps
print()
Check Answer
Spots
1name = Ava
2age = 12

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Giant Isopod' badge — Patient Builder, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. Which line causes a NameError? score = 10 print(scor)
A. score = 10
B. print(scor) ✓
The variable was created as score, but the code asks for scor. Python does not know the name scor, so it raises a NameError.
2. What happens when this code runs? print(total) total = 5
A. It prints 5
B. NameError, because total is used before it is assigned ✓
Python reads line by line. On line 1 total does not exist yet, so Python raises a NameError. Assign the variable first, then use it.
3. Which code runs without a NameError?
A. name = 'Mia' print(name) ✓
B. name = 'Mia' print(Name)
Capital letters matter in Python. name and Name are two different names, so Name has not been defined and causes a NameError.
4. Which code prints the word hello without a NameError?
A. print('hello') ✓
B. print(hello)
Text needs quotes. Without quotes Python thinks hello is a variable name. It has not been defined, so it raises a NameError.
5. True or false: Python treats age and Age as the same variable.
A. False ✓
B. True
Python is case-sensitive. age and Age are different names, so using the wrong capitals can cause a NameError.

Match the Pairs

print(scor) → NameError: the variable was spelt score, so Python does not know scor
print(Hello) → NameError: Hello has no quotes, so Python thinks it is a variable name
Capital letters matter, so Name and name are two different names → name = "Sam" print(Name)
A variable must be assigned before it is used, or Python does not know it yet → total = 5 print(total)
print(points) points = 10 → The variable points is used on line 1 before it is assigned on line 2, so Python raises a NameError. Assign it first, then print it.
colour = "blue" print(colur) → The name is misspelt as colur, but the variable is colour. Fix the typo so both spellings match.

Key Term

NameError
An error Python raises when code uses a variable or function name it does not know, often from a typo, wrong capitals, missing quotes or using a name before it is assigned.

Fill in the Blanks

1. score = 10 print(score)
Hint: Type the variable name exactly as it was created on the line above.
2. total = 5 + 2 print(total)
Hint: Type the variable name that must be assigned before the print line uses it.
3. Name = "Zoe" print(Name)
Hint: Type the variable name, matching the capital letter used when it was assigned.
4. pet = "cat" print("My pet is", pet)
Hint: Type the variable name with no quote marks, so Python reads it as a stored name and not as plain text.
5. for i in range(3): print(i)
Hint: Type the loop variable name that the print line uses.

Spot the Error

Question 1
A name = Ava
B age = 12
C print(name)
D print(age)
Line A — Ava is text, so it needs quotes. Without them Python looks for a variable called Ava and raises a NameError. It should be name = "Ava".
Question 2
A score = 10
B score = scor + 5
C print(score)
Line B — scor is a misspelling of score. Python does not know a name called scor, so it raises a NameError. It should be score = score + 5.
Question 3
A colour = "blue"
B print("Sky is", Colour)
C print(colour)
Line B — Capital letters matter in Python. Colour is not the same name as colour, so this raises a NameError. It should be print("Sky is", colour).
Question 4
A def say_Hi():
B print("Hi!")
C say_hi()
Line A — The function is defined as say_Hi, but the call uses say_hi. Capital letters matter, so Python raises a NameError at the call. It should be def say_hi():.
Question 5
A name = "Zoe"
B age = 13
C print("Hello", name)
D print(Age, age)
Line D — Age is a label, so it needs quotes. Without them Python looks for a variable named Age and raises a NameError. It should be print("Age", age).

Student with a class code? Join your class →