Stuck at Iterating over a list in a function


#1


n = [3, 5, 7]
def total(numbers):
    result=0
    for i in numbers:
        result=result+numbers[i]
    return result
print total(n)

I as totally stuck at this quiz.

Is there any error on my code ??

my code keep making an error... like this

Traceback (most recent call last):
File "C:/Python27/0729-2.py", line 7, in
print total(n)
File "C:/Python27/0729-2.py", line 5, in total
result=result+numbers[i]
IndexError: list index out of range


#2

@bpj777
With the

for i in numbers:

i will have the actual Array-item-Value
and not the item-index-nr as you thought.


#3

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