Median


#1



help



Oops, try again. median([4, 5, 5, 4]) resulted in an error: unsupported operand type(s) for /: 'list' and 'int'


def median(list1):
    list1.sort()
    if len(list1) % 2 == 0:
        a = len(list1/2)
        b = a - 1 
        median = (list1[a]+list1[b])/2.0
    else:
        c = int(len(list1)-1)/2
        median = list1[c]
    return median


#2

this line:

a = len(list1/2)

currently you are trying to divide the list by 2 (not sure how that works) rather then dividing the length of the list by 2


#3

thanks! i chnaged it and now its work
thanks alot!


#4