Modifying an element of a list in a function


#1

This is my code and I really have no clue what to do:

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

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

And this is the error message it gives:

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


#2

@papayabubble Hey,
Remember you're in a function and the parameter "x" has to be included within the local scope. Not n, unless you're calling the function, from which you did.
Hope this helps!


#3

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


#4

Thanks I made it through!
@hayatonogami
@infinitycoder14


#5

This code work for me. Any stuck on this challenge.

def list_function(x):
x[1] = x[1]+3
return x
n = [3, 5, 7]
print list_function(n)

as it is.


#6

That worked for me as well