16.median(help me)


#1



the answer is right,but i do not idea why it told me i am wrong


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


def median(mylist):
    newlist = sorted(mylist)
    print newlist
    sizelist=len(mylist)
    if sizelist==1:
        return newlist[sizelist-1]
    elif (sizelist+1)%2==0:
        return int(newlist[(sizelist+1)/2-1])
    else:
        return int(newlist[sizelist/2-1]),int(newlist[(sizelist/2)])
print median([4]) 
print median([2,3])
print median([4, 5, 5, 4]) 
print median([4, 5, 5, 4,6,4,2]) .


#2

you return a tuple with the two middle values, you should return a float with an average of this values


#3

thank you very much.


#4