Median


#1


Ok I can't seem to understand why my code does not work. In fact I get the error that ([4 5 5 4]) prints the median 5.0 insted of 4.5. Which is nuts because the median is 5.


def median(lista):
    ep=len(lista)
    if ep==1:
        med=lista[0]
    elif ep%2==0:
        med=(lista[(ep/2)-1]+lista[(ep/2)])/2.0
        
    else:
        med=lista[(ep/2)-1]
    return med


#2

You forgot to sort the list lista!

hint**
Read the instruction and theory!


#3

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