V
18

Just tried to make a simple Python counter and it broke after 999,997 clicks

I wrote a 'for i in range(1000000)' loop to test something, but it stopped early because I accidentally put 'print(i)' inside an 'if i == 999997' block, which taught me to always check my indentation before blaming the language.
3 comments

Log in to join the discussion

Log In
3 Comments
davis.olivia
That indentation trap gets everyone at some point. Read a blog post once where a guy lost hours because a single space messed up his whole data script. Python's whitespace thing is cool for clean code but man does it bite you when you're tired. Always run a quick check on those loops before assuming the computer is broken. The machine is usually right, we just told it to do the wrong thing.
5
hannah_fisher58
What if the real problem is we're still writing code like it's on paper? I mean, our editors have color coding and auto complete but they don't really guard against indentation slips. Maybe the fix isn't being more careful, it's tools that actually see structure and warn you before you run the broken script. Idk, it just feels like we're solving the same basic mistake over and over instead of making it impossible to make.
7
grant155
grant15520h ago
Totally agree. Linters and formatters like black for Python should be built in by default. They catch those indentation errors instantly and auto fix them. It's wild that we still manually debug spaces and tabs in 2024.
5