CurriculumReading Python Error Messages, for KidsThe Debugging Procedure

A Real Python Debugging Procedure, Step by Step

Read it, say what you expected, change ONE thing, run again — the loop that actually works.

Lesson 4 of 4PROAges 10+
See what PRO unlocks →

The Debugging Procedure

You've fixed crashes, named exception types, and found a bug with no error message at all. Here's the procedure tying it together — five steps, every time.

1. Read the error — or notice there isn't one. 2. Say what you EXPECTED. 3. Say what ACTUALLY happened. 4. Change ONE thing. 5. Run again.

Step 4 is the one everyone skips under pressure — changing three things at once because you're not sure which one matters.

The problem: if you change three things and it works, you don't actually know WHICH change fixed it. If it still doesn't work, you don't know which change made it worse.

One change, one run, one clear answer each time. Slower per step, but genuinely faster overall — because you stop guessing.

This works whether there's a traceback (segments 1-2) or dead silence (segment 3) — expected vs. actual is the constant, whatever form the mismatch takes.

Check your understanding

A child changes three lines at once, reruns, and the bug is gone. What's the problem with this approach?

  • They don't actually know WHICH of the three changes fixed it
  • There's no problem — the bug is fixed, that's what matters

Why: They don't know which change actually mattered — maybe only one of the three fixed anything, and the other two were unrelated or even risky. Changing ONE thing at a time is slower per step but means every result actually teaches you something.

Which step of the procedure applies even when there's NO error message at all?

  • Say what you expected vs. what actually happened — that comparison works with or without a traceback
  • None of them — the procedure only works when there's a real error to read

Why: Expected vs. actual — that's the core of the whole procedure, and it works identically whether Python gave you a traceback (segments 1-2) or stayed completely silent while doing the wrong thing (segment 3). The traceback is a HELPFUL shortcut when it exists, not the only way in.

What you'll practice

This code crashes with a KeyError. Before fixing anything: read the error, then fix stats to use a key that actually exists — level, not lvl.

Unlock this lesson with PRO →

More from this topic

The Debugging Procedure is one lesson inside Reading Python Error Messages, for Kids — see the full lesson order and what the whole topic covers.

View the full topic →