How does the accumulator pattern collapse a running sum into one tidy `for` loop — and where does an off-by-one `range` quietly bite?
Short drills on what this video just taught. Write the code, run the checks, and reveal the answer only if you are stuck.
The accumulator total is already started at 0 for you.
Use a for loop and the accumulator pattern to add up every integer from 0 through 9, leaving the result in total.
Accumulating a sum across iterations
Write the program that sums range(10) into mysum, trace the value of mysum after each value of i, and record the printed total 45.
Debugging an off-by-one range with print
Reproduce the inclusive-sum bug where range(start, end) with 3 and 5 gives 7, add a print of i inside the loop, and fix the stop to end + 1 for 12.
Factorial rewritten with for and range
Write the factorial using for i in range(1, x + 1), mark which lines of the while version it replaces, and note that for loops fit a known iteration count.