Modifying an element of a list in a function


def list_function(x):
x[1] = x[1] - 2

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

Oops, try again. list_function([5, 5]) returned None, did you remember to return the result?

can any one help me to solve this problem?


can i have the link to the lesson?
also, you didn't return anything inside of your function, but i would like to read the instructions to figure out what you're supposed to return.

Edit: found the lesson, it actually asks you to add 3 to x[1], so that would look like

x[1] += 3


x[1] = x[1] + 3

Either way, after you add three to x[1], you need to return x, which is the parameter, but it will return the list, which includes the updated x[1].


this code i had written. could you plz see once.


Step 3 says to return the list. Just add to your function code:

return x


This is my program. Is any thing went wrong? could you please tell me.

def list_function(x):
x[1] = x[1] - 2
return x

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

[3, 3, 7]

Oops, try again. list_function([3, 5]) returned [3, 3] instead of [3, 8]


In the instructions it says to add 3.


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