Why this code is not working?



Oops, try again. median([4, 5, 5, 4]) returned 4 instead of 4.5

What is the value of k? I though it would be 9 and if it is divided by 2 then it should give 4.5 for the value of m.

why m is 4 but not 4.5 in this case?

def median(a):
    if len(b) % 2 == 0: # if it is a even set
        return m
    elif len(b)==1:
        return b[0]
        return b[(len(b)/2)]


because is python2, dividing two integers gives a integer as result (if needs be, python floors the numbers), you could solve this problem by dividing by 2.0 which is a float, this way you will get a float as result


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