Exercise: median


#1



Exercise: median

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


When I run my program, give me this error: "Oops, try again. median([4, 5, 5, 4]) returned 5.0 instead of 4.5".

I check with that list in my program and the result it's correct (4.5).
Here's my code:

import math
def median(lista):
    length = len(lista)
    if length % 2 == 0:
        med = lista[length / 2] + lista[length / 2 - 1]
        med = float(med) / 2
        return med
    else:
        length = float(length) 
        length = length / 2
        return lista[int(math.ceil(length-1))]
    


sorted_list = sorted([4, 5, 5, 4])
median(sorted_list)


What's wong? Please help me.
Thanks!


#2

you need to sort the list inside the function.


#3

Gracias !! Ya se resolvió.


#4