10. Modifying an element of a list in a function



Here is my code plus the error message that I'm getting:

I've been scrolling through the discussion forum, and the same code seems to work for other programmers. What could I be doing wrong? :confused: :weary:


are you sure you are at exercise 10? All you need to do is:
Add 3 to the item at index one of the list.
so if the list is [5,0] then 3 should be added to the second item (index 1) so the result is [5,3], you don't need to loop over the items in the list, and you don't need to multiply in this exercise


The code you have written is not intended for this lesson. You just need to overwrite the value of x[i] to x[i]+3.
Here's my code for reference. I hope ur problem will get solved.

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

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


That worked! Thanks! :thumbsup: