15/15 median



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):
    mid = len(x)/2       #middle number len(x) if divided by 2
    if len(x) < 2:
        return x[0]
        if len(x) % 2 == 0:  #len(x) is even
            return float(x[mid] + x[mid-1])/2 # 2 middle values averaged
            return float(x[mid])    #middle value


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.


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