Practice makes perfect error [Oops, try again]


As a result I get this error: Oops, try again. median([1]) returned 6.0 instead of 1

I try this code in PyCharm and it's working, I tried couple of time with different lists and everytime it's getting me the correct result. What's wrong here?

a = [1,3,20,8,4,10]
b = sorted(a)
x = (len(b) // 2)

def median(number):
    if len(b) % 2 == 1:
        return b[x]
        print b[x]

        y = (b[len(b)/2]+b[(len(b)/2)-1])/2.0
        return y
    print y

print "Median value of list",a, "is:", median(a)


everything we need to calculate the median should be in the function, so when we call the function multiply times:

print "Median value of list",a, "is:", median(a)
print median([4,5,5,4])


So easy. Thanks a lot!


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