# Modifying an element of a list in a function

#1

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?

#2

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``

or

``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].

#3

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

#4

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

``return x``

#5

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)

output
[3, 3, 7]
None

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

#6

In the instructions it says to add 3.

#7

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