List manipulation in functions - Answer not being accepted


#1



https://www.codecademy.com/courses/python-beginner-nzzVa/2/4?curriculum_id=4f89dab3d788890003000096


It asks to append 9 to the list by calling the list_extender method. Even though 9 is getting appended to the list in the correct way, it still throws the error of not returning the list. I also tried storing the result in the 'lst' and then return lst separately. That too did not work.


As per the code written:

9 should be appended to the list


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

print list_extender(n)

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


#2

HI you should first append() 9 then return lst like that

.....
    lst.append(9)
    retrun lst

print list_extender(n)

#3

Thanks alot. But why couldn't we return the list directly when we can return the other data types directly?


#4

@abhilav.sharma19
Have you tried a refresh Browser
as your code seems to be Ok.

++++ reset of session *****************
As you are manipulating with objects
under certain circumstances you can shoot your Browser in an
inconsistent state.

Therefor it is of an advantage to know that you have 2 reset facilities:

One is the use of the F5-key which does a refresh Browser

and

Two, select&copy your code
Then use the Reset Code button of the course-window,
then paste your code back in.

Addendum
General Notes:
Always refresh the browser after making corrections:
CTRL f5 ( if on Windows or Linux)
CMD r ( if on a MAC).
CTRL 0 to reset browser zoom


#5

that question has been answer here


HOpe that could help you


#6

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