10. Modifying an element of a list in a function



Change list_function so that:

Add 3 to the item at index one of the list.
Store the result back into index one.
Return the list.

Without adding any code, I hit 'save & submit.'

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


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


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

et cetera

Why does the error message change when the code remains untouched?

def list_function(x):
    return x[1]

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


I'm guessing that codecademy has setup the scoring engine to test the code with a random number that way you can't tailor your code to the one input it's going to test with.


same problem here, any tips to fix it?


We have to return the List not the element (after updating it). So

 return x  (but not x[1])


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