# Lists and Functions

#1

Oops, try again. list_function([3, 6]) returned [3, 8, 7] instead of [3, 9]

Oops, try again. list_function([0, 3]) returned [3, 8, 7] instead of [0, 6]

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

i think the funtion change the valor of the second element to the list, and i think the code do this well, and i understand the code is ok , but the web return my a error
and when i try to save and submit same code again , the error change.

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

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

#2

yes, it does, you did this right

then you should return the modified list, in which variable is the modified list stored? And are you returning this variable/modified list?

#3

i think the problem is i dont understand correctly the instructions .
the instructions say:
Change list_function so that:

1ºAdd 3 to the item at index one of the list.
x[1]=x[1]+3
2ºStore the result back into index one.
i dont understand this part , i supose when put this line
x[1]=x[1]+3
they do first and second instruction at the same time .
i am wrong?
3ºReturn the list.
return n

for my i follow the instructions but i do anything wrong

#4

the point of a function is that it will work for multiply lists:

``````def list_function(x):
print x

n = [3, 5, 7]
o = [1,2,3]
p = [4,5,6]
q = [7,8,9]
list_function(n)
list_function(o)
list_function(p)
list_function(q)``````

see how we supply different lists as argument on function call? And how this lists are then stored in the function parameter `x`?

So then we modify the list `x`, we should also return `x`

#5

thanks you very much , i understand now . my problem are no understand correctly the instruction 3.
1ºAdd 3 to the item at index one of the list.
(tthis list aren n= [3, 5, 7] )
2ºStore the result back into index one.
(that is no at probllem )
3ºReturn the list.
(but this list are not n= [3, 5, 7] )
(are a list for store the list with modifiquet arguments)
my problem are no understand the instructions .

#6

no, the list you need to `return` is in `x` ( the function parameter)

Function can be a bit confusing

#7

yes i understand x is the new list like n list but have modificated items by the funtion . and the funtion work in every list what i pass to arg in funtion . now they work

#8

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