The median is the value sitting in the middle once the numbers are lined up in order. Half the list is below it, half above.
Task: write median(values) returning that middle value, rounded to 4 decimal places.
The two cases you have to handle:
[2, 4, 7, 9] that's (4 + 7) / 2 = 5.5.Also worth knowing:
values is never empty, and it arrives in no particular order — sort it yourself first, or "the middle" means nothing.statistics.median; the point is to see how the two cases differ.The median only cares about position, never size — so a wildly large value at the end barely moves it.