All problems
Cumulative Sum
Problem
Return the running totals of data as a list, so element i is the sum of data[0] through data[i]. Return an empty list for empty input.
Hint
Keep a running total and append after each addition.
Test cases
case 1
in: [[1,2,3]]
expected: [1,3,6]
case 2
in: [[]]
expected: []
case 3
in: [[5,-2,0]]
expected: [5,3,3]
case 4
in: [[1.5,2.5]]
expected: [1.5,4]
case 5
in: [[-1,-2,-3]]
expected: [-1,-3,-6]
Starter codePython
def cumulative_sum(data):
# Your code here
pass5 test cases · run your code against them in the editor