11/18


#1

n = [3, 5, 7]
list_extender(lst)
list_extender.append(9)
print lst

print list_extender(n)

Traceback (most recent call last):
File "python", line 2, in
NameError: name 'lst' is not defined

i need help anyone ,pls ?


#2

this is your code corrected with comments

n = [3, 5, 7]

#first you need to add def to 
#make it a function definition
def list_extender(lst):
    #whenever you call this method
    # you want to add 9 to input list
    lst.append(9)
    print lst

#no need to call print here since we are printing the list
#in the method already
list_extender(n)

#3

n = [3, 5, 7]
def list_extender(lst):
lst.append(9)
print lst
list_extender(n)

Oops, try again. list_extender([1, 2, 3, 4]) returned None, did you remember to return the result?


#4

then instead of print lst

do

return lst

#5

Perfect , thanks a lot for your help man :smiley: 1:


#6

Happy coding buddy :smile:


#7

hi i'm having a problem. tried what you guys have mentioned and its still giving me incorrect syntax

This is what i have so far:

n = [3, 5, 7]

Add your function here

n = [3, 5, 7]
def list_extender(lst):
lst.append(9)
return lst
list_extender(n)

this is the message that comes up:

File "python", line 6
SyntaxError: 'return' outside function


#8

n = [3, 5, 7]
def list_extender(lst):
lst.append(9)
return lst

print list_extender

don"t forget to print list_extender without the (n) part
The above code should def work , it did for me :smile:


#9

in addition to to what @modafalla has said remember python is strict on indentation. You are getting that error because your return statement is outside the function and return can only be used in methods. to solve this indent your return statement line 4 spaces to the right