Programming
Python Debugging Practice — Find & Fix Bugs
Exercises
Off-By-One Error
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
- 1Pick an exercise from the list (filter by topic or level).
- 2Read the task and run the buggy code to see what goes wrong.
- 3Edit the code in “Your fix” and press Check my fix — it runs and is compared with the expected output.
- 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.
Related tools
Python Line-by-Line Executor — Step Execution
Run Python one line at a time: see the line about to run, output as it is printed, changed variables and line counts.
Python Variable Trace Table Generator
Generate a trace table automatically: one row per executed line, every variable after the line, and its output.
Python Quiz Generator — Practice Challenges
Practice Python with multiple-choice questions on variables, loops, functions, lists, and more.