🎙️
11

My first Python script printed 'Hello World' 100 times instead of once

I was following a basic tutorial and typed 'for i in range(100):' above my print line, not realizing the indent would make it loop. I ran it and my terminal just flooded with greetings. It took me ten minutes to figure out I needed to delete that line. Now I really get why indentation matters in Python, it's not just for looks. Has anyone else had a simple typo cause a huge mess like that?
3 comments

Log in to join the discussion

Log In
3 Comments
williamb29
williamb291mo ago
Oh man, that's a classic one lol. I used to think the strict indentation was just annoying, but mistakes like that show you why it's actually important. It forces you to write clearer code from the start.
6
the_alice
the_alice1mo ago
Honestly @williamb29, "forces you to write clearer code" is so true. Tbh I fought it for ages until a messed up loop cost me an hour. Now I get it.
8
hunt.sage
hunt.sage1mo ago
Actually, I've never found strict rules make my code better. They just add extra steps that slow me down. Good code comes from careful thinking, not forced formatting.
5