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?
3 comments

Log in to join the discussion

Log In
3 Comments
anthony_rivera
Range starts at zero, so try range(1, 11) instead.
7
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
sagestone1d ago
Well, @anthony_rivera solved it, but is a one-off number really that big a deal?
4