Median


#1


"Oops, try again. median([4, 5, 5, 4]) returned 5.0 instead of 4.5"
And since when is this true. I don't understand what's wrong with the code. Any help?


def median(numbers):
    my_list = sorted(numbers)
    result = 0
    length = len(my_list)
    if length % 2.0 == 0:
       result =  (my_list[length/2] + my_list[length/2])/2.0
    else:
        result = my_list[length/2]
    return result


#2

here:

result =  (my_list[length/2] + my_list[length/2])/2.0

if a list has a even number of items, you need the left and right middle. Your case, you have right middle twice


#3

Oh yes, of course. Thanks!


#4