11. List manipulation in functions: Bug with the course?


#1


https://www.codecademy.com/courses/python-beginner-nzzVa/2/4?curriculum_id=4f89dab3d788890003000096

I have what I believe is the right way to do this excercise as the interpreter on the right gives me the correct output, but the error at the bottom of the page says otherwise.

Output box:
[1, 2, 3, 4, 9]
None

Error message:
Oops, try again. list_extender([1, 2, 3, 4]) returned [1, 2, 3, 4, 9, 9] instead of [1, 2, 3, 4, 9]

These things contradict each other. Am I doing something wrong?


n = [1, 2, 3, 4]
# Add your function here
def list_extender(lst):
    n.append(9)
    return n

print list_extender(n)


#2

look at this code:

n = [1, 2, 3, 4]
# Add your function here
def list_extender(lst):
    n.append(9)
    return n

print list_extender(n)
print list_extender([5,6,7])

i added another function call, your function should work for both function calls, it doesn't. the second function call should print [5,6,7,9], but that doesn't happen

function which works for a single list is a pointless function


#3

Thank you for your help. I appreciate you not giving me the answer but instead pointing me towards it. I got it to work:)


#4

Then i assume you understand how the function parameter (lst) plays an important roll here?

You're welcome, i think you learn more if i just point you in the right direction and you figure it out :slight_smile:


#5

Hi I was wondering how does 1st work as a function parameter since it has both letters and numbers?
I just ended up changing everything to n it so simplify it and it seems to work:
n = [3, 5, 7]

Add your function here

def list_extender (n):
n.append(9)
return n
print list_extender(n)


#6

what first one? i don't see anything which has both letters and numbers, can you be more specific?


#7

I think you're mis-reading it the same way I did: the parameter for "list_extender" is supposed to be 'lst' (short for "LIST"), not '1st' (short for "FIRST").


#8

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