13
PSA: I was writing my loops backwards for months
I was working on a small project to track my daily water intake, just a simple console app. For the longest time, I'd write my for loops like `for i in 0 to 10` and then get confused when my list only showed 9 items. I thought Python was just being weird! The moment it clicked was last Tuesday when I was following a tutorial on Codecademy. The instructor said, 'Remember, the stop number is exclusive,' and I had to pause the video. I went back to my old code and realized I'd been adding 1 to my range end point to try and force it to work, which made everything messy. Now I just write `for i in range(0, 11)` and it works perfectly. Has anyone else had a simple rule like that just completely pass them by when they were starting out?
3 comments
Log in to join the discussion
Log In3 Comments
jennyh551mo ago
That range function got me too, for weeks.
10
dakota_taylor391mo ago
Weeks? How did you even function? That's brutal.
7
cameron_webb13d ago
@jennyh55 did the opposite trick ever bite you, like thinking the start number was exclusive?
8