[beginner] What's wrong?

sohcahtoa82 at gmail.com sohcahtoa82 at gmail.com
Fri Apr 1 18:44:26 EDT 2016


On Friday, April 1, 2016 at 3:10:51 PM UTC-7, Michael Okuntsov wrote:
> Nevermind. for j in range(1,8) should be for j in range(8).

I can't tell you how many times I've gotten bit in the ass with that off-by-one mistake whenever I use a range that doesn't start at zero.

I know that if I want to loop 10 times and I either want to start at zero or just don't care about the actual number, I use `for i in range(10)`.  But if I want to loop from 10 to 20, my first instinct is to write `for i in range(10, 20)`, and then I'm left figuring out why my loop isn't executing the last step.



More information about the Python-list mailing list