Member-only story
Find a Bug in Python Code: A Little Thing Does So Much
Even the smallest characters can introduce big problems

In this article, I will show you a tiny little bug in Python. It’s common, as I have made it too often. Maybe a dozen, maybe even twenty times — far more often than I consider acceptable. But since I’ve made it so often, I usually spot it rather easily.
Below, I will explain a strategy you can use to find this and other bugs. While this seems like our little game, this is actually how you could approach debugging.
Your task is to find one or more bugs in the code. How to do it? It’s your call, so choose your method. You can, for instance:
- Just read the code and the traceback, and try to find the bug. This is easier for some snippets than for others.
- Copy and paste the code to your IDE, text editor, or whatever you work with. Then run the app and try to find the bug using the traceback. You can also use the simplest non-interactive tools that help in debugging, like
print()
, thelogging
module, and the like. - Copy and paste the code to your editor/IDE as above, then use the debugger of your choice to find the bug(s). This is interactive debugging.
None of these approaches is better than the others. Each of them teaches different skills, so you should try all of them. Perhaps a good approach is to start with method (1), then, if that doesn’t work, try method (2), and if you still cannot find the bug, try method (3).
That way, you move from the easiest and quickest method to the most advanced one. This partially reflects real-life coding practice, which is how I usually proceed. Honestly, I usually move immediately to the third method when I do not see the bug after the first glance, that is, when using the first method.
Do not underestimate the second method, though. It’s important and teaches something of extraordinary importance: reading and understanding of traceback.
So, let’s jump into the code. Try to find the bug. The good news is that this one is easy to fix. But to fix it, you have to find it. When you succeed in finding it, fixing it is a matter of seconds.