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):
    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


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.


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