Modifying an Element in a list of a function


My code is generating the correct output, but I am receiving the following error code:

list_function([5, 4]) returned 7 instead of [5, 7]

I don't know what this means or how to correct this error.

Thank you for your help.

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

n = [3, 5, 7]
print n


you need to return the whole list, not just the second item of the list


But, when I ran it on my PC. It ran good. Idk why.
Same code like him/her.


there are no syntax problems with the code, the problem is that you return the first item in the list, while you should return the whole list


you are returning only one element in the list with your function

return x[1] should be just return x

then just print the function with respect to the list n


one way that helped me to grasp this was to understand that the print statement is working for the function. It is going to print what is returned by the function, at least for this exercise. The exercise instructs you to print the whole list, not just the first element. by only returning x[1], you are telling the print statement to only print x[1]. As people mentioned above it, you should return the whole list with just 'return x'


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