V
2

My Python loop printed the wrong thing and I can't figure out why

I was trying to make a simple counter that goes from 1 to 10, but it started at 0 and stopped at 9. I used `for i in range(10):` because I thought that was right. Anyone know the fix for this?
4 comments

Log in to join the discussion

Log In
4 Comments
anthony_rivera
Range starts at zero, so try range(1, 11) instead.
7
abby_morgan18
My first boss paid me for 9 hours when my time card clearly said 10. That missing hour felt huge when rent was due. These small counting errors build up in real life, not just in code. It's a pattern of systems being just a little bit off from how people actually live.
8
hannahcraig
Just a one-off number? Tell that to the guy who got paid for 10 hours when he worked 11. Zero-based counting trips everyone up at first, doesn't it? It's the kind of tiny mistake that makes a whole program do the wrong thing. You'd think counting would be the easy part.
3
sagestone
sagestone1mo ago
Well, @anthony_rivera solved it, but is a one-off number really that big a deal?
4