# Practis makes perfect - Median

#1
``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)

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

#2

``[1,999,1000]``

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

#3

thank you mate , i have not read this well

#4

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

#5

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 , and if you have enaught time to explaine this .

#6

`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

#7

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