Iterating over a list in a function


#1



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


I'm not sure what other variable I should use in my function?


Replace this line with your code. 
n = [3, 5, 7]

def total(numbers):
    result = 0
    for n in numbers: 
        n + result
    return result

print total(n)


#2

look at this code:

i = 10
print i # 10
i + 5
print i # 10
i = i + 5
print i # 15

now look at where you add n to result, you will need to update the result variable.


#3

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