Median error


#1


https://www.codecademy.com/courses/python-intermediate-en-rCQKw/2/5?curriculum_id=4f89dab3d788890003000096#

File "python", line 9
return list_median
^
SyntaxError: invalid syntax

May I ask why line 9 is a syntax error?


def median(my_list):
    my_list = my_list.sort()
    list_median = 1
    if len(my_list) % 2 == 1:
        list_median = my_list[(len(my_list) / 2.0) + 1]
        return list_median
    else:
       list_median =( my_list[(len(my_list) / 2.0)] + my_list[((len(my_list) / 2.0) + 1) / 2 ]
       return list_median


#2

Hi,

I think you didn't close the bracket after the equals sign.


#3

Thank you for your quick response. That solved my problem but now I get this error
"median([1]) resulted in an error: object of type 'NoneType' has no len()"

What does this mean?


#4

Well, if you do:

my_list.sort()

it will sort the list, and store it in my_list, if you do:

my_list = my_list.sort()

will be an empty list because of how sorts works, you can read about it here, this code has more issues, but this should help you going.