11.List manipulation in functions


#1

I don't get what's going on here.

Its asking me to do this...
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.

So I start of with n = 3, 5, 7. from the previous task and it doesn't ask me to change it, but it throws me "Oops, try again. listextender([1, 2, 3, 4]) returned [3, 5, 7, 9, 9] instead of [1, 2, 3, 4, 9]"_

So, I change n = 1, 2, 3, 4 (which it hasn't asked me to)...

To which it throws me "Oops, try again. listextender([1, 2, 3, 4]) returned [1, 2, 3, 4, 9, 9] instead of [1, 2, 3, 4, 9]_
". But as you can see in the terminal it didn't thrhow a double 9..

what's going on?

`


#2

You should return lst not return n :slight_smile:
You're manipulating lst, so that's what you would want to return.


#3

Ahh, weird though, 'cause now I'm getting

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

code...

n = [3, 5, 7]

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


print list_extender(n)

#4

you need to append 9 to lst though, not n


#5

I'm an idiot :frowning:... got it now, thanks.


#6

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