15/15


#1

Hi, I cant figure out why my code didnt work out.
def median(x):
a = len(x)
x = sorted(x)

if a == 1:
    median = x[0]
elif a % 2 != 0:
    b = int(a//2)
    median = x[b]
else:
    c=int(a/2)
    median = (int(x[c-1]) + int(x[c])) /2
return median

It write a message error that median([4, 5, 5, 4]) returned 4 instead of 4.5 but in fact it did make 4.5!


#2
median = (int(x[c-1]) + int(x[c])) /2

Here you devide an integer by another integer. Python 2.x will return another int for that.