Medians


#1


def median(lis):
li=sorted(lis)
n=len(li)
if n==1:
return li[0]
elif n%2==0:
a=n/2
res=(li[a]+li[a+1])/2.0
return res
else:
return li[(n/2)-0.5]

this code does not works so plss help me


Replace this line with your code.


#2

Why the -0.5 in your last line?


#3

so that if 5/2 the answer will be 2.5 so the ans and -0.5 can give 2


#4

actually the list is not sorted i don't know y that happened


#5

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