Build a running total
Trace an accumulator through a sequence and avoid resetting it inside a loop.
In this lesson
- It starts with a question. If a total is reset to zero before every sale, will it remember earlier sales?
- The idea you will find. Start once, then add each amount once. — An accumulator begins at a useful starting value, often zero. For each sale, replace total with the old total plus that sale. Initialise before the loop so earlier sales remain included.
- How you learn it. By doing: a number line, putting things in order.
- Length. 8 short steps. Progress saves on this phone.
Part of Python market notebook
Follow a fictional market notebook through inputs, totals, data structures and tested functions. Complete every activity inside FijiLearn.