Find Median from list?


#1

def median(n):
n.sort()
num = len(n)
if num % 2 == 0:
return (n[num/2 - 1] + n[num/2])/2.0
else:
return n[int(num -1)]/2
I did use above code to find medain from the list as per instructed bt codeacademy. But I didn’t understand the uses of num % 2 == 0, what is it’s use in here ?


#2

Try executing it for different values for num and see what you end up doing

and/or refer to how you manually compute median, because you need to do the same thing then