code: def median(array):
      
      n = len(array)
  
      if n < 1:
          return 0
      elif n == 1:
          return array[0]
  
      sorted_vals = sorted(array)
      midpoint = int(n / 2)
      if n % 2 == 1:
          return sorted_vals[midpoint]
      else:
          return (sorted_vals[midpoint - 1] + sorted_vals[midpoint]) / 2.0
docs: Return the median value of a list of numbers.