Lab Four (Ex. 10.3)

The objective of this exercise was to create a function that takes a list of numbers and produces the cumulative sum.

Source Code:

def cumulative (a):
cumulative = []
add = 0
for x in a:
add += x
cumulative.append(add)

return cumulative
a = [10,5,10]
print (cumulative(a))
a = [5,6,7]
print (cumulative (a))
a = [45,20,15]
print (cumulative (a))

this is the one

Leave a Reply

Your email address will not be published. Required fields are marked *