Median


#1



def median(x):
    l=sorted(x)
    y= len(l)/2
    if len(x)%2==0:
        return float((x[y+1]+x[(y-1)]))/2
    else:
        return x[y]


Its say that the median ([6,8,12,2,23]) returned 8 instead of 12 but I'm sure the median is 12.


#2

Remember to use the sorted list, not the original. The median is 8.


#3

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