manyspikes

Challenge 1: Calculating medians

Initialising environment...

Instructions

Implement a function called median which takes as input a sequence (e.g. a list or a tuple) of values and returns the median of the data values.

For a sorted sequence x with N data points, the median is defined as follows:

  • If the number of input values is odd, then the median is the central value of x
  • If the number of input values is even, then the median is the average between the two central values of x.

For instance, if x=[1, 2, 3, 4, 5] the median of x should be 3.

If x=[1, 2, 3, 4], its median would be (2+3)/2.