List manipulation in functions


#1



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

print list_extender(n)

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


#2

HI this line

n.append(9)

you should use the parameter of the function which is lst instead of n


#3

why pls ?:slight_smile:


#4

Because you should make a function that will add the number 9 to any list so that why you should put lst
if you n your function will look like that

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

print list_extender(n)
#Output
[1,2,3,4,9]

in this case the this function will only add the number 9 to the list n instead of to any list


#5

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