10. Modifying an element of a list in a function ERROR


#1

I have given this code and checked with other posts on why it does not work. Can anyone help?

def list_function(x):
    x[1] = x[1] + 3
    return x[1]

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

Oops, try again. list_function([0, 3]) returned 6 instead of [0, 6]


#2

you should return the whole list, not the second item of the list


#3

Ok, I tried:

def list_function(x):
    x[1] = x[1] + 3
    n.append(x[1])
    return n

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

Oops, try again. list_function([6, 1]) returned [3, 8, 7, 8, 4] instead of [6, 4]


#4

why did you append to list? i don't see it any where in the instructions


#5

def list_function(x):
    x[1] = x[1] + 3
    return n

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

Oops, try again. list_function([6, 6]) returned [3, 8, 7] instead of [6, 9]

Does it want me to remove index 1? Or change it?


#6

you modify the list correctly, but now you need to return the modified list (x)


#7

Oh, I see. I returned the wrong list.


#9