
def mean(values):
    return float(sum(values)) / len(values)

def median(values):
    middle = (len(values) - 1) // 2

    if len(values) % 2:
        return values[middle]
    else:
        return mean(values[middle:middle + 2])



def mean(values):
    return float(sum(values)) / len(values)

def quantile(p):
    def bound_quantile(values):
        ix = int(len(values) * p)

        if len(values) % 2:
            return values[ix]
        elif ix < 1:
            return values[0]
        else:
            return mean(values[ix - 1:ix + 1])

    return bound_quantile

Q0 = min
Q1 = quantile(0.25)
Q2 = median = quantile(0.5)
Q3 = quantile(0.75)
Q4 = max

Add a rudimentary quantile factory function.
Add a rudimentary quantile factory function.

+ 
  
  def mean(values):
      return float(sum(values)) / len(values)
  
- def median(values):
-     middle = (len(values) - 1) // 2
+ def quantile(p):
+     def bound_quantile(values):
+         ix = int(len(values) * p)
  
-     if len(values) % 2:
+         if len(values) % 2:
-         return values[middle]
+             return values[ix]
+         elif ix < 1:
+             return values[0]
-     else:
+         else:
-         return mean(values[middle:middle + 2])
+             return mean(values[ix - 1:ix + 1])
  
+     return bound_quantile
+ 
+ Q0 = min
+ Q1 = quantile(0.25)
+ Q2 = median = quantile(0.5)
+ Q3 = quantile(0.75)
+ Q4 = max
+ 
Add a rudimentary quantile factory function.
## Code Before:

def mean(values):
    return float(sum(values)) / len(values)

def median(values):
    middle = (len(values) - 1) // 2

    if len(values) % 2:
        return values[middle]
    else:
        return mean(values[middle:middle + 2])

## Instruction:
Add a rudimentary quantile factory function.
## Code After:


def mean(values):
    return float(sum(values)) / len(values)

def quantile(p):
    def bound_quantile(values):
        ix = int(len(values) * p)

        if len(values) % 2:
            return values[ix]
        elif ix < 1:
            return values[0]
        else:
            return mean(values[ix - 1:ix + 1])

    return bound_quantile

Q0 = min
Q1 = quantile(0.25)
Q2 = median = quantile(0.5)
Q3 = quantile(0.75)
Q4 = max
