← VCE Software Development U3O1

Runtime errors in Python

An error that stops a program while it runs, shown as a named error like NameError, ValueError or ZeroDivisionError. Read the message to find the problem.

Understanding Runtime errors in Python in VCE Software Development U3O1

What it does: int("hello") cannot turn the word into a number. The program stops with a ValueError while it runs. Start prints, then 10 / 0 causes a ZeroDivisionError. The program stops, so End never prints. Python raises a NameError when you use a variable name that has not been created yet. Check the spelling or create the variable first. The message tells you the type of error (like NameError) and which line caused it. This helps you find the problem fast. A runtime error only stops the program at the broken line. Earlier lines such as print('Hi') have already run.

Common mistakes: The variable totl was never created, so Python stops with a NameError. The name must match the variable made earlier: total. You cannot divide by zero. Python stops with a ZeroDivisionError. Divide by a number that is not zero, such as 4.

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
Which error does this code cause? print(score) (score was never created)
NameErrorZeroDivisionError
Matches
name = "Sam" print(nmae)
↓
The variable is spelled nmae in print(), but it was created as name. This causes a NameError. Fix it by typing print(name).
Applying
Meanings
Term
runtime error
Meaning
An error that stops a program while it runs, shown as a named error like NameError, ValueError or ZeroDivisionError. Read the message to find the problem.
Practice
print("Start")
Testing
Gaps
print()
Check Answer
Spots
3total = players + pizzas
4print("Total:", totl)

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

The 'Hermit Crab' badge — Definition Collector, 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 error does this code cause? print(score) (score was never created)
A. ZeroDivisionError
B. NameError ✓
Python raises a NameError when you use a variable name that has not been created yet. Check the spelling or create the variable first.
2. What happens when this code runs? age = int("hello")
A. ValueError: int() cannot turn the text into a whole number ✓
B. SyntaxError: the brackets are missing
The code is written correctly, but "hello" is not a number. This stops the program while it runs, so it is a ValueError.
3. Which line causes a ZeroDivisionError?
A. print(0 / 10)
B. print(10 / 0) ✓
You cannot divide by zero. 0 / 10 is fine and gives 0.0, but 10 / 0 stops the program.
4. True or false: A runtime error is found only while the program is running.
A. True ✓
B. False
Python starts the program and then stops at the line that breaks. The lines before it have already run.
5. When a program crashes with an error message, what should you read first?
A. The error name and the line number ✓
B. Nothing, just run it again
The message tells you the type of error (like NameError) and which line caused it. This helps you find the problem fast.

Match the Pairs

NameError: name 'score' is not defined → The program used a variable name that was never created, or it was spelled differently
ZeroDivisionError: division by zero → The program tried to divide a number by 0, so it stopped running
A ValueError happens when int() gets text that is not a whole number → age = int("hello")
A runtime error stops the program at the line that fails, so later lines never run → print("Start") x = 10 / 0 print("End")
name = "Sam" print(nmae) → The variable is spelled nmae in print(), but it was created as name. This causes a NameError. Fix it by typing print(name).
total = 50 share = total / 0 → Dividing by 0 causes a ZeroDivisionError. Fix it by dividing by a number that is not 0, such as total / 5.

Key Term

runtime error
An error that stops a program while it runs, shown as a named error like NameError, ValueError or ZeroDivisionError. Read the message to find the problem.

Fill in the Blanks

1. score = 10 print(score)
Hint: Type the variable name that was created on line 1, so Python does not raise a NameError.
2. word = "cat" num = int(word) # causes a ValueError
Hint: Type the name of the runtime error shown when int() cannot convert the text to a number.
3. people = 0 if people != 0: print(10 / people)
Hint: Type the variable name being checked so the program never divides by zero.
4. print(total) # total was never made: NameError
Hint: Type the name of the runtime error shown when a variable is used before it exists.
5. # This line causes a ZeroDivisionError print(10 / 0)
Hint: Type the number that you cannot divide by in Python.

Spot the Error

Question 1
A players = 4
B pizzas = 2
C total = players + pizzas
D print("Total:", totl)
Line D — The variable totl was never created, so Python stops with a NameError. The name must match the variable made earlier: total.
Question 2
A points = 20
B average = points / 0
C print(average)
Line B — You cannot divide by zero. Python stops with a ZeroDivisionError. Divide by a number that is not zero, such as 4.
Question 3
A age = int("twelve")
B next_age = age + 1
C print("Next year:", next_age)
Line A — int() can only turn digit text like "12" into a number. The word "twelve" causes a ValueError. Use int("12").
Question 4
A name = "Mia"
B score = 10
C print(Mia, "scored", score)
Line C — Mia has no quote marks, so Python thinks it is a variable name that does not exist. This is a NameError. Use the variable name instead of Mia.
Question 5
A total = 30
B count = 5
C mean = total / (count - 5)
D print(mean)
Line C — count - 5 is 0, so the program divides by zero and stops with a ZeroDivisionError. It should be total / count.

Student with a class code? Join your class →