10/18


#1

Here's my code:

def list_function(x): #define function#
x[1] = x[1] + 3 #add 3 to index 1#
return x[1] #store result#

n = [3, 5, 7] #new list#
list_function(n) #pass in new list#
print n #print list#

It prints:

[3, 8, 7]
None

As near as I can tell, that's the correct answer, but I keep getting various error messages like:

Oops, try again. list_function([0, 1]) returned 4 instead of [0, 4]

or

Oops, try again. list_function([1, 0]) returned 3 instead of [1, 3]

or

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

It literally changes every time with no change to my code at all!

Is this a bug? What am I doing wrong here? Devs?


#2

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

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

This works; needed to return x, not x[1].

Doesn't explain the changing error messages though......


#3

Thabk You, that worked for me, i had included the return x[1] by mistake instead of return x as you point out. here is my code with the indents all working:

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

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

This returned the answer :
[3, 8, 7]
None