Iterating over a list in a function


#1



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


Keep getting the error message: Oops, try again. total([0, 3, 6]) returned 3 instead of 9


I think my problem is that i'm setting the function to terminate at len(numbers) and so it's not including the last number in the list, 6. I have no idea how to fix this though.

I have quadruple checked my indentation but it could also be this.
Any help would be greatly appreciated so I can advance!


def total(numbers):
    result=0
    for number in range(0,len(numbers)):
        result+=number
    return result


#2

here:

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

using range() will give you the indexes for your numbers list, so either use the indexes range give you to retrieve values from your numbers list and add them to result, or don't use range at all, which give you direct access to values in numbers list


#3

Thank you for your help!


#7