Median


#1

where am i going wrong its throwing NoneType error ,help needed!

def median(t):
    l=t.sort()
    if len(t)%2==0:
       x= l[(len(t)/2.0)-1]+l[len(t)/2.0]
    else:
       x= l[len(t)/2.0]
    return x
print median([7,12,3,1,6])

#2

i have figured it out
def median(t):
t.sort()
if len(t)%2==0:
x= (t[(len(t)/2)-1]+t[len(t)/2])/2.0
else:
x= t[len(t)/2]
return x
print median([4,5,5,4])


#3

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