Median

1
2
3
4
5
6
7
8
9
10
11
import math
nums = [5, 9, 10, 11, 22, 1, 0, -1] #< Fill list with values
nums.sort() #< Sort the list in ascending order
try:
    mid_num = ( len( nums ) - 1) / 2
    median = nums[ mid_num ]
except TypeError:   #<  There were an even amount of values
    # Make sure to type results of math.floor/ceil to int for use in list indices
    ceil = int( math.ceil( mid_num ) )
    floor = int( math.floor( mid_num ) )
    median = ( nums[ ceil ] + nums[ floor ] ) / 2

Lower Quartile

1
2
3
4
5
import math
nums = [5, 9, 10, 11, 22, 1, 0, -1] #< Fill list with values
nums.sort() #< Sort the list in ascending order
low_mid = int( round( ( len(nums) + 1 ) / 4.0 )1 ) #< Thanks @Alex (comments)
lq = nums[low_mid]

Upper Quartile

1
2
3
4
5
6
7
8
9
10
11
import math
nums = [5, 9, 10, 11, 22, 1, 0, -1] #< Fill list with values
nums.sort() #< Sort the list in ascending order
try:
    high_mid = ( len( nums ) - 1 ) * 0.75
    uq = nums[ high_mid ]
except TypeError:   #<  There were an even amount of values
    # Make sure to type results of math.floor/ceil to int for use in list indices
    ceil = int( math.ceil( high_mid ) )
    floor = int( math.floor( high_mid ) )
    uq = ( nums[ ceil ] + nums[ floor ] ) / 2

Credits

http://www.mathsteacher.com.au/year9/ch17_statistics/06_quartiles/quartiles.htm

0