Exercise 9 - Using element from a list in a function


#1



Lists and Functions - Exercise 9 - Using element from a list in a function


#I know that the code that is expected to be written is this:
def list_function(x):
    return x[1]

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

#HOWEVER,
#Why can't we just do this?

def list_function(x):
    return x

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

Codecademy doesn't accept this solution saying something weird:
"Oops, try again. list_function([1, 8, 6]) returned [1, 8, 6] instead of 8"

While, if I try this code in a terminal, it works perfectly and prints "5" as expected.


Replace this line with your code.


#2

codecademy runs multiply functions calls on your function to test if the function is correct, plus your function now doesn't do what it is designed to do


#3

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