Exercise · Lists · lesson 10 of 11
Exercise: running totals
Write a function running_totals(nums) that returns a new list of running totals: each of its elements is the sum of the elements of nums from the start through the same position inclusive. The function does not change the list nums itself.
running_totals([1, 2, 3])→[1, 3, 6]running_totals([3, -1, -2])→[3, 2, 0]running_totals([])→[]
Constraints: nums holds from 0 to 1000 integers from -1000000 to 1000000, negative ones included; for an empty list the result is an empty list; after the call, nums holds the same elements in the same order.
Do not add extra imports unless the task says so explicitly.
Subscribe to take the course
The course is free. Sign in with Telegram and subscribe to the channel to open every lesson.