Modifying an element of a list in a function . why doesn't it work?


#1



Modifying an element of a list in a function

I'm using exactly the same logic as the example in the exercise. The print out that I get is correct : [3, 8, 7] but I get the error message Oops, try again. list_function([4, 3]) returned [3, 11, 7] instead of [4, 6]


Replace this line with your code. 
def list_function(x):
    n[1]=n[1]+3
    return n

n = [3, 5, 7]
list_function(n)
print n


#2

def list_function(x):

Function's parameter is (list )x not n?


#3

I got it.
def list_function(x):
x[1]=x[1]+3
return x

n = [3, 5, 7]
list_function(n)
print n

Thank you


#4

edit your final working answer so others just don't copy it and use it. :thumbsup:


#5

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