BugHunt

Python loop exercises

Most beginner bugs live inside a loop: it runs one time too many or too few, it never stops, or it returns after the first pass. These exercises are short loops with exactly one of those mistakes.

Trace the loop by hand for a small input, find where it goes wrong, and fix it. Infinite loops are stopped safely after a few seconds, so you cannot hang your browser.

See the 20 exercisesOr follow the 30-day path

The loops bugs you will meet

The exercises

Errors you might be searching for

More Python practice by topic

Questions

What happens if my fix creates an infinite loop?

The test is stopped after a few seconds and marked as timed out. Your browser stays responsive.

Can I see the loop run step by step?

Yes. After a run, the line-by-line view shows every variable at every step, which is the fastest way to see where a loop goes wrong.