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 In4 Comments
anthony_rivera1mo ago
Range starts at zero, so try range(1, 11) instead.
7
abby_morgan1811d ago
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
hannahcraig1mo ago
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