Iterating over a list in a function


#1



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


Oops, try again. total([0, 3, 6]) resulted in an error: list index out of range


n = [3, 5, 7]

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


#2

i contains the values from the list, not the indexes, so you can add i to result directly


#4

Thank you very much !!


#5

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