Iterating over a list in a function


#1

can any one tell me where my code went wrong?when i use second method.


#2

The range you are adding is, [0, 1, 2], the indices. Add numbers[n].


#3

now i have to add 3. is it correct


#4

You have to add the values in the list, not the indices from the range.

for i in range(len(numbers)):
    result += numbers[i]

#5

kk,i got it.Thank you


#6

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