Median


#1



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


Hello , can anyone help me with my code?

median([4, 5, 5, 4]) returned 4 instead of 4.5


Replace this line with your code. 
def median(x):
    x.sort()
    total = 0
    for i in range(0,len(x)):
        total += x[i] 
    return (total/len(x))
    
print median([1,3,6,7,12])

gives me 5 instead of 6


#2

You need to provide a way for the function to work correctly when the number of items is even by taking the mean average of the two "middle" items.


#3

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