Median


#1



why is this not working?


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


#2

dividing an integer by an integer will result in a integer, if needs be, the number is floored. You will need to do something with float


#3

to get a float median, using:
float(n)/2 or n/(2.0)


#4

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