Iterating over a list in a function


Oops, try again. total([0, 3, 6]) returned 0 instead of 9

I'm trying to use the length() function to compete this exercise but i don't know how to do it... help?

n = [3, 5, 7]

def total(numbers):
    result = 0
    for i in range( len(numbers) ) :
        result = numbers[i] + result
        return result



this is an indentation problem. The line return result is too indented and should be at the same level as the line result = 0

In the current state of the code, the loop is executed only once and then the function returns result. So you get the first value of numbers.



Try this:

for i in range(0, len(numbers)):

this helped me