Instructions:
Define a function called summer() that sums the elements in a list of numbers. summer() takes a single list argument. First you need to initialize an accumulator to zero, then use a for-loop to add the value of each element in the list, and finally return the total sum to the calling program.
Question:
I know how to do this very easily with the sum() function but I am not allowed to use this. I must find a way to sum a lists value and print that sum.
i.e
>>> x = [9, 3, 21, 15]
>>> summer(x)
48
What I've tried:
xlist=[9,3,21,15]
sumed=0
def summer(x):
for i in x:
sumed+=i
print(sumed)
summer(xlist)
I keep getting 'sumed' ref. before assignment with this one