#205 · Lists · Beginner · 25 XP · about 4 min
A running total adds numbers up as it goes and notes the sum after each one, the way a bank statement shows the balance after every payment. Write running_total(nums) that returns a new list where each item is the sum of all the numbers up to and including that position.
An empty list gives an empty list.
running_total([1, 2, 3, 4]) # returns [1, 3, 6, 10] running_total([5, -2, 7]) # returns [5, 3, 10] running_total([8000, 0, 12000]) # returns [8000, 8000, 20000]
In the first example the totals are 1, then 1 + 2, then 1 + 2 + 3, then 1 + 2 + 3 + 4.
First solves only, ranked by stars and then time.