Median


#1

Please help me!
I don' t understand what is wrong with my code.


def median(l1):
    a = sorted(l1)
    x = len(a) // 2
    if len(a) % 2 != 0:
        return l1[x]
    else:
        y = x - 1
        res = (l1[x] + l1[y]) / 2.0
        return res


#2

Ah, i found that silly mistake!!!
return a[x] and res = (a[x] + a[y]) / 2.0


#3

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