15. Iterating over a list in a function ... Peeps help out fellow student


#1



https://www.codecademy.com/courses/python-beginner-nzzVa/3/4?curriculum_id=4f89dab3d788890003000096


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


Any ideas guys ? Have been cracking my head over this for an hour now ......


n = [3, 5, 7]
def total(n):
    result = 0
    for i in range(len(n)):
        result += n[i]
        return result

total(n)


#2

a function ends the moment a return keyword is reached, which in your case happens in the first run of the loop

You might want to change the indent of your return so the whole for loop can run


#3

Dammit ! Freaking indent ! lol

THANKS SO MUCH MATE !