Loops
for i in range(1, n + 1) runs the loop body once for each integer from 1 up
to (but not including) n + 1 - so range(1, 6) gives 1, 2, 3, 4, 5. That
+ 1 trips everyone up at first: range's upper bound is exclusive, so you
add one to actually include n.
A common pattern is a running total: start a variable at 0 before the loop,
then add to it on every pass. By the time the loop ends, it holds the answer
you built up one step at a time.
Your task: write total_up_to(n), returning the sum of every integer from
1 to n, inclusive, using a loop.
You'll practice:
- Looping with
for and range()
- Accumulating a result in a variable