Practis makes perfect - Median

Please someone help me .Why this code does not work at last leson?

def median(number_list):
    sum_number = 0  
    for number in number_list:
        last += number
    total = sum_number / len(number_list)
    return total 

print median([1,2,3,4,5,6,7,8])


uhm... if your list is:


the median is the middle value, so 999. It has nothing to do with averages. i am afraid you have to go back to the drawing board


thank you mate , i have not read this well


Did you figure it out? If you need more help with median, post an updated version of your code + error message + question


You are awesome ! , i can't understand this result = (x[(y / 2)] + x[(y / 2) - 1]) / 2.0 , i saw this in other post and i'm not good at math :blush: , and if you have enaught time to explaine this .


y contains the length of the list. For list with a odd number of items, to get the median value you need the two middle indexes (len / 2 and len / 2 -1), add them together and divide them


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