Creating a summation function


Why is it that my code below does not add up all the numbers but only prints 7?

n = [3, 5, 7]

def total(numbers):
for item in numbers:
return total

print total(n)



Because you are resetting the value to zero each iteration. Only the last iteration is accumulated.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.