11. List manipulation in functions


I am having a hard time understanding Python.. can somebody please tell me what I am doing wrong and explain to me why it is not working?

Here is the assignment:
Define a function called list_extender that has one parameter lst.
Inside the function, append the number 9 to lst.
Then return the modified list.

Here is my code:

n = [3, 5, 7]
# Add your function here
def list_extender(1st):
    return n
print list_extender(n)

Thank you in advance.


well i am not sure that the assignment is saying to use the parameter 1st. maybe its saying to use l s t instead of 1 s t. Try my help. I was confused at my time too.


@arcrunner08150, is right. You should use the function parameter 1st.

The function parameter will hold whatever you supply as argument when calling the function:

print list_extender(n)

in this case, 1st will now hold the list stored n

by doing this, your function works for multiply lists instead of just 1 list

also, variable names can't start with a number, try using lst instead of 1st


@arcrunner08150 @stetim94

Thank you both for your help. I think you both can see my confusion with 1st and lst. Arc, I changed it to lst and it introduced a new error, but I found out what it was. I changed n.append to lst.append and changed return n to return lst. Here is the code:

n = [3, 5, 7]
# Add your function here
def list_extender(lst):
    return lst
print list_extender(n)


this totally makes sense, but it keeps throwing an error that i dint return the result. could anyone help me with the reason?


yea we can, go here, make a new topic, fill in the template, this way, we can help you best :slight_smile: