15. Iterating over a list in a function



Have no idea what I'm doing wrong. Can anyone help pls?

n = [3, 5, 7]

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


Hi @myeates,

Instead of this ...

    for number in n:

... what you need to do is iterate through numbers ...

    for number in numbers:

Then this statement inside the loop will work correctly ...

        result += number


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