Programming

Python Debugging Practice — Find & Fix Bugs

Practise debugging with 20 short Python programs that each contain one classic bug: off-by-one loops, missing returns, mutable default arguments, aliasing, modifying a list while looping, scope errors, missing base cases, float comparison and more. Fix the code and check it by running it with real Python.
Real Python 3.11 in your browser20 exercises

Exercises

0/20 solved

Off-By-One Error

Loopsbeginner

This code should print numbers 1 to 5, but something is wrong.

Buggy code

for i in range(5):
    print(i)

Your fix

Progress is saved in this browser only.

How to use this tool

  1. 1Pick an exercise from the list (filter by topic or level).
  2. 2Read the task and run the buggy code to see what goes wrong.
  3. 3Edit the code in “Your fix” and press Check my fix — it runs and is compared with the expected output.
  4. 4Use the hint if you are stuck, or reveal the solution and explanation.

Frequently asked questions

Your code and the reference solution both run with real Python; your fix passes when it prints exactly the same output without an error.

Off-by-one loops and indexes, missing returns, mutable default arguments, list aliasing, removing items while looping, infinite loops, UnboundLocalError, missing base cases, KeyError, float comparison, late-binding lambdas and more.

Solved exercises are remembered in this browser only.

No. The tool runs real Python 3.11 (Pyodide, Python compiled to WebAssembly) inside your browser. The first run downloads the runtime (about 10 MB) once per visit; your code never leaves your device.