15/15 median


#1


Hi.

Can anyone help me here. I keep getting the following error message:

Oops, try again. median([1]) returned 6.0 instead of 1

But the code seems to work when I run it. I've gone over and over but can''t see what's wrong. A view from someone else would be helpful. Thanks

def median(X):
    x.sort() 
    mid = len(x)/2       #middle number len(x) if divided by 2
    if len(x) < 2:
        return x[0]
    else:
        if len(x) % 2 == 0:  #len(x) is even
            return float(x[mid] + x[mid-1])/2 # 2 middle values averaged
        else:
            return float(x[mid])    #middle value


#2

Your function does not use its parameter at all as you can tell by sending your function any argument at all and still get the same result.


#3

You used capital X in the def and x in the rest if the code