Debugging a program with print() and trace tables
Debugging tool: print a variable at key points, then compare each value with your trace table of what it should be. The first mismatch shows where the bug is.
Understanding Debugging a program with print() and trace tables in VCE Software Development U3O1
What it does: Printing at a key point (after the loop) gives you a real value to compare with the expected 6 in the trace table. If they differ, the bug is before this line. A logic error lets the program run but gives the wrong result. A misspelled function name is a syntax or name error, and Python reports it. Testing one function at a time narrows down where the bug is. Changing lots of things at once makes it harder to find.
Common mistakes: A for loop header must end with a colon. This syntax error stops the program before any print() runs. It should be: for n in [2, 4, 6]:. This is a logic error. The trace table says double(5) should give 10, but print() shows 7 because + was used. It should be: return x * 2.
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 168–177) and word search (Modules 168–193).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
print(variable)Fill in the Blanks
Spot the Error
Student with a class code? Join your class →