Read a filtered accumulator
Track total as the loop visits each value.
def total_even(values):
total = 0
for value in values:
if value % 2 == 0:
total += value
return total
Only values with a remainder of zero when divided by two are added to the accumulator.
What does total_even([1, 2, 4, 5]) return?
Why it matters: Following accumulator updates one iteration at a time makes loop results predictable.