12
My little victory with a stubborn for loop
I was trying to make a list of numbers in Python, but my loop kept leaving the last one out (so annoying). After staring at it for an hour, I tried using `range(1, 11)` instead of `range(1, 10)` and it finally printed all ten numbers. It seems so simple now, but figuring out that the second number isn't included was a big deal for me. Has anyone else had a 'duh' moment with something like range()?
3 comments
Log in to join the discussion
Log In3 Comments
the_jason3mo ago
Oh man, that "second number isn't included" thing gets everyone. My friend spent a whole day trying to figure out why his list was one short before he realized the same thing. What was the project you were working on?
10
nathan_barnes2mo ago
Was it a game thing? My buddy had the EXACT same headache @the_jason. He was trying to make a simple countdown timer for a game jam project. He used range(1, 60) for the seconds and could NOT figure out why his timer stopped at 59. He kept checking his loop logic for hours. It finally clicked when he printed the whole list out and saw the 60 was just... missing. That moment of pure facepalm is a rite of passage.
1