← VCE Software Development U3O1

Reading an error message and traceback

The start of Python's error report. It names the error type (like NameError) and the line number where it happened, so you know where to start looking for the bug.

Understanding Reading an error message and traceback in VCE Software Development U3O1

What it does: The error type names the problem: the index used was bigger than the last position in the list. The traceback names TypeError and explains that a string and an integer cannot be joined with +. A NameError means a variable or function name is used before it exists. Check line 7 for a typo or a missing assignment. The closing bracket is missing, so Python cannot read the line. Broken grammar in code is a SyntaxError. total has not been given a value, so Python does not know the name. That is a NameError. List positions start at 0, so the valid indexes are 0, 1 and 2. Index 3 is out of range, which is an IndexError.

Common mistakes: The traceback would say NameError: name 'bonnus' is not defined, on line 3. The variable is spelled bonus, so the line should be total = score + bonus. A SyntaxError is reported on line 1 because the colon at the end of the for line is missing. It should be for i in range(3):.

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 156–166) and word search (Modules 142–166).

Take this worksheet further — free with Cloodit

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

Learning
Duo
A traceback says 'NameError: name score is not defined' on line 7. What does this mean?
Python found a name on line 7 that was never createdPython could not find line 7 in the file
Matches
File "app.py", line 5 print("Hi" ^ SyntaxError: '(' was never closed
↓
A SyntaxError means the code breaks Python's grammar rules. Here a closing bracket is missing, so add ) at the end of the line.
Applying
Meanings
Term
Traceback (most recent call last):
Meaning
The start of Python's error report. It names the error type (like NameError) and the line number where it happened, so you know where to start looking for the bug.
Practice
Traceback (most recent call last):
Testing
Gaps
: name 'scor' is not defined
Check Answer
Spots
2bonus = 5
3total = score + bonnus

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

The 'Sand Cat' badge — Precision Prowler, 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. A traceback says 'NameError: name score is not defined' on line 7. What does this mean?
A. Python found a name on line 7 that was never created ✓
B. Python could not find line 7 in the file
A NameError means a variable or function name is used before it exists. Check line 7 for a typo or a missing assignment.
2. Where should you start looking for a bug when you read a traceback?
A. At the line number the error message gives ✓
B. At line 1 of the program, every time
The traceback names the line where Python noticed the problem, so that line is the best place to start.
3. Which error type does this code cause? print('Hello'
A. SyntaxError ✓
B. NameError
The closing bracket is missing, so Python cannot read the line. Broken grammar in code is a SyntaxError.
4. Which error type does this code cause? print(total) (total was never created)
A. TypeError
B. NameError ✓
total has not been given a value, so Python does not know the name. That is a NameError.
5. Which error type does this code cause? print('Age: ' + 15)
A. IndexError
B. TypeError ✓
You cannot add a string and an integer with +. Using the wrong data type for an operation is a TypeError.

Match the Pairs

NameError: name 'score' is not defined → Python met a variable name it has never seen, often from a typo or using it before it was created
File "game.py", line 12, in <module> → The traceback line that shows which file and which line number to start looking for the bug
An IndexError means you asked for a list position that does not exist → IndexError: list index out of range
A TypeError happens when you combine values of the wrong types, like a string and an integer → TypeError: can only concatenate str (not "int") to str
File "app.py", line 5 print("Hi" ^ SyntaxError: '(' was never closed → A SyntaxError means the code breaks Python's grammar rules. Here a closing bracket is missing, so add ) at the end of the line.
names = ['Ava', 'Ben'] print(names[2]) IndexError: list index out of range → The list only has positions 0 and 1, so index 2 does not exist. Use names[1] to get the last item.

Key Term

Traceback (most recent call last):
The start of Python's error report. It names the error type (like NameError) and the line number where it happened, so you know where to start looking for the bug.

Fill in the Blanks

1. NameError: name 'scor' is not defined
Hint: Type the error type Python reports when a variable name has not been defined.
2. age = 15 print("Age: " + age) TypeError: can only concatenate str
Hint: Type the error type shown when you join a string and a number the wrong way.
3. colours = ["red", "blue"] print(colours[5]) IndexError: list index out of range
Hint: Type the error type for using a list position that does not exist.
4. print("Hello" SyntaxError: '(' was never closed
Hint: Type the error type Python gives when code is written with incorrect grammar, such as a missing bracket.
5. File "main.py", line 3, in <module>
Hint: Type the word that comes before the number showing where the error happened.

Spot the Error

Question 1
A score = 10
B bonus = 5
C total = score + bonnus
D print(total)
Line C — The traceback would say NameError: name 'bonnus' is not defined, on line 3. The variable is spelled bonus, so the line should be total = score + bonus.
Question 2
A for i in range(3)
B print(i)
C print('Done')
Line A — A SyntaxError is reported on line 1 because the colon at the end of the for line is missing. It should be for i in range(3):
Question 3
A pets = ['cat', 'dog', 'fish']
B print(pets[0])
C print(pets[1])
D print(pets[3])
Line D — The list has 3 items, so the valid indexes are 0, 1 and 2. Index 3 gives IndexError: list index out of range on line 4. It should be pets[2].
Question 4
A age = 15
B msg = 'Age: ' + age
C print(msg)
Line B — You can't add a string and an integer. Python gives a TypeError on line 2. Convert the number with str(age).
Question 5
A name = 'Sam'
B points = 3
C print(name)
D print(Points)
Line D — Python is case-sensitive. The variable is points, not Points, so the traceback shows NameError on line 4. It should be print(points).

Student with a class code? Join your class →