List manipulation in functions


#1



List manipulation in functions


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


Judging off of the other threads, I feel that my code is correct and is returning what I am asked


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


print list_extender(n)


#2

You need to call a function put you're printing it instead.

list_extender(n) //this is a function call

#3

@trevlawson ,

This accesses the global variable, n, rather than the function parameter, lst ...

n.append(9)

Instead, you should access the function parameter, lst, so that you append to whatever list is passed to the list_extender function when it is called..


#4


n = [3, 5, 7] # Add your function here def list_extender(lst): lst.append(4) return lst print list_extender(n)
That is my code and it's printing the right answer to the console at the same time it throwing some errors like "Oops, try again. list_extender([1, 2, 3, 4]) returned [1, 2, 3, 4, 4] instead of [1, 2, 3, 4, 9]" what am I missing?


#5

This appends the number, 4, to the list ...

lst.append(4)

However, Codecademy wants you to append the number, 9, to the list.


#6

Thanks. I didn't saw that.


#7

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