Hi Everyone, if anyone can help I would much appreciate it.
I'm trying to write a code to get the median of a list
my code seem to mess up when I have multiple item of the same value in a list. it keep spitting out this message: " Oops, try again. median([1, 34, 1, 6, 8, 0]) returned 1 instead of 3.5"
which is right btw, but I don't understand why is my code not taking route 'a' instead of 'c' since r is an even number
def median(n): m = sorted(n) result = 0 r = len(m)/2.0 if r % 2 == 0: print 'a' result =(m[int(r-1)] + m[int(r)])/2.0 elif r==0: print 'b' result= m else: print 'c' result= m[int(r-0.5)] return result