15. Median


#1



https://www.codecademy.com/courses/python-intermediate-en-rCQKw/2/5?curriculum_id=4f89dab3d788890003000096


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


Why doesn't this code work?


def median(_list_):
    m1 = len(_list_) / 2
    if len(_list_) % 2 == 0:
        m2 = m1 - 1
        return ((_list_[m2] + _list_[m1])/ 2)
    else:
        return _list_[int(m1)]
        
print median([1,2,3,4,5,6,7,8,9,10])


#2

it seems you forgot to sort the list. If you need more help, post an updated version of your code


#5

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