Debugging with print()
A debug print. Add a line like this to show a variable's value while the program runs, so you can spot where it goes wrong. Put one inside a loop to watch it change, then remove it once fixed.
Understanding Debugging with print() in VCE Software Development U3O1
What it does: The debug print sits straight after the line that changes total, so you can see the result of that calculation. Commenting out or deleting the debug line stops it appearing in the final program's output. A debug print shows you the real value of a variable, so you can see where it stops being what you expected. Python does not need a label, but it makes the output much easier to read when you have several debug prints. Printing values lets you check your guess with evidence. The first place a value looks wrong is close to the bug. Putting a print inside a loop shows the values every time round, so you can see exactly when score goes wrong.
Common mistakes: There is a comma missing between the label and the variable. The debug print must be print("total =", total) so Python knows they are two separate things to show. Python cares about capital letters. The variable is called count, not Count, so the debug print causes a NameError. It should be print("count =", count).
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.
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("total =", total)Fill in the Blanks
Spot the Error
Student with a class code? Join your class →