Iterating over a list in a function


#1

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

Hi, below is the error I'm getting for this exercise:
Oops, try again. total([0, 3, 6]) returned 6 instead of 9

My code is below:

Any help would be appreciated! Thanks!

n = [3, 5, 7]

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


#2

the shorthand you use should be +=, not =+


#3

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