Iterating over a list in a function


Traceback (most recent call last):
File "python", line 9, in
TypeError: 'function' object has no attribute 'getitem'

I have no idea what went wrong with my code. Plz help me

n = [3, 5, 7]

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

print total[n]


result = result + numbers(i)

to get a value of a list we use [] not ()

and here


to call a function we use () not []


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