Median error


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
       list_median =( my_list[(len(my_list) / 2.0)] + my_list[((len(my_list) / 2.0) + 1) / 2 ]
       return list_median



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


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?


Well, if you do:


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.