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 4
  • PRO
  • Ages 10+
  • 3 hands-on levels
See what PRO unlocksA one-time $49.99 purchase. Topics 1–3 are free.

The dragon explains

The Debugging Procedure

  1. The dragon: 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.

  2. The dragon: 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.

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

  4. The dragon: 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.

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

  6. The dragon: 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.

Quick check

Check your understanding

Say your answer out loud before reading the marked one. Every wrong option is a mistake real beginners make.

  1. Question 1 of 2

    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 itCorrect
    • 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.

  2. Question 2 of 2

    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 tracebackCorrect
    • 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.

In the game

What you'll practice

Three levels in the game: one guided first try with the shape of the answer already there, then two to solve on your own.

  1. 1

    GuidedYour first try

    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.

  2. +2

    PracticeTwo more, on your own

This lesson is part of PRO.

PRO is a one-time $49.99 purchase, no subscription, and unlocks this whole topic along with everything else. Topics 1–3 are free, start to finish.

Unlock this lesson with PRO

Stuck three times? The game offers the answer — unasked.