For Codecademy developers ! Found a glitch


This is a default code that welcomes a student:

def list_function(x):
    return x

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

Instructions says:

Change line 2 so that list_function returns only the item stored in index one of x, rather than the entire x list.

I changed a bit more than just line two. This is a code that worked:

def list_function(x):
    return x[1]

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

Instructions are misguiding at this exercise. Don't know if intentionally or not. Just letting you know.


Hi, @markiscoding ,

Yes, you changed more than you needed to, but it did not change the meaning of the program, so your code passed.

Although you changed the name of the variable, n, to x in the last two lines, there are still two different variables in the program. In the first two lines of your code, x is a variable that is local to the function, list_function. That is because it is specified as a parameter in the function header.

However, in the last two lines, x is a different variable that is global in scope, as was the case with the original variable, n, given in the default code.


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