Find the bug in the Python code

Find the line with the bug

The function below is almost right. One single line is wrong. Read what it should do, look at the case where it fails, and click the guilty line.

How does Find the bug work?

Every level shows a short function that is almost right, what it should do, and one case where it fails. Exactly one line is wrong. Click that line.

There are 100 levels and they get harder by the KIND of defect, not by the size of the code: the first ones are a flipped operator or a wrong constant, the last ones are an off-by-one in a range or a return that fell inside the loop.

Why is the code in English?

Because keywords and identifiers are English in every programming course, and translating for or return would teach the wrong thing. The sentence that says what the function should do is translated; the code is not.

Are the bugs guaranteed to be real bugs?

Yes, and that is measured rather than assumed. Every planted defect is run against the correct version on several inputs, and it only becomes a level if the two disagree somewhere. Four of the 57 defects written by hand changed nothing at all and were thrown away.

Do I need to know Python?

It helps, but the functions were picked to be readable by anyone who has seen a loop and an if. No library, no syntax beyond the basics.

Is my progress saved?

The furthest level you solved is kept in your own browser. There is no account and nothing is sent anywhere.