Maden please help


#1

what is wrong with my code please help anyone

def median(l):
    length = len(l)
    new = sorted(l)
    print new
    if length == 1:
        return new[0]
    if length % 2 == 0:
        one = new[length / 2]
        two = new[(length / 2) - 1]
        res = (one + two) / 2.0
        return res
    if length % 2 != 0:
        odd1 = new[length]
        odd2 = new[(length / 2) - 1]
        res1 = (odd1 + odd2) / 2.0
        return res1

#2

for odd numbers:

if length % 2 != 0:

you only need to return the middle number (length / 2), that is all


#3

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