Modifying an element of a list in a function


#1


Oops, try again. list_function([1, 2]) returned 5 instead of [1, 5] is the error msg.


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

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


#2

Question:
Change list_function so that:

Add 3 to the item at index one of the list.
Store the result back into index one.
Return the list.


#3

do you return the list?


#4

Hi uzumakinaruto99!

After looking throughout the forums, I noticed that the issue that you have is simply..

"return x[1]" should be "return x"

That should let you go on to the next lesson :slight_smile:


#5

No it doesn't really solve the problem.


#6

you reply to raidedvillager, with a quote of uzumakinaruto99 and "it" doesn't solve the problem, what is "it"? What is your question? Or is a question?


#7

The above line of rectification was my response, the suggestion didn't work in my case.


#8

But the suggestion is for uzumakinaruto99 code, not yours? You might have a different problem altogether. By responding that this solution doesn't work for you, without any further details is very confusing. Do you still have a problem? If so, please make a new topic so we can help.


#9

Thank you @raidedvillager and @stetim94


#10