Iterating over a list in a function


#1




when i use the method1 (for number in numbers)- it's all ok,
but when i try to use method2 i have an error

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

i want to try both methods

what i'm doing wrong?


n = [3, 5, 7]

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


#2

range will give you indexes:

n = [3, 5, 7]

def total(numbers):
    result = 0
    for number in range(len(numbers)):
        print number
    return result
    
print total(n)

so then you need to number as index to get the items in the numbers list


#3

thanks. i'm understand


#4