Median


#1


Oops, try again. median([1, 34, 1, 6, 8, 0]) returned 5.5 instead of 3.5


def median(med):
    med.sort()
    core = len(med)
    if core % 2 == 0:
        return (med[core/2] + med[core/2] - 1) /2.0
    elif core % 2 != 0:
        return med[core/2]


#2

here:

med[core/2] - 1

you want to get the left middle value. What you currently do is get the right middle value, and then subtract one from the right middle value


#3

So if i add 1 i should get the result?


#4

no. After we we sort the list we have:

median([0, 1, 1, 6, 8, 34])

so what you want to is get the middle two values (left middle: 1 and right middle: 6), add them together and divide by two which should result in 3.5

what you are currently doing is retrieving right middle value twice (6 and 6)

you should subtract one of the index here:

med[core/2] - 1

not of the value. (which is what you are currently doing)


#5

oh i see thank you for your help


#6