Skip to content
DeepForgeby svx
All problems
MediumStatisticsst-023

Quartiles (Tukey Hinges)

Problem

Return [Q1, Q3] using Tukey hinges: split the sorted data into lower and upper halves, including the median in both halves when n is odd. Q1 is the median of the lower half and Q3 is the median of the upper half. Return [0.0, 0.0] for empty input.

Hint

The inclusive split for odd n means both halves contain the median.

Test cases

case 1
in: [[1,2,3,4,5]]
expected: [2,4]
case 2
in: [[1,2,3,4]]
expected: [1.5,3.5]
case 3
in: [[1,2,3,4,5,6,7,8,9]]
expected: [3,7]
case 4
in: [[7]]
expected: [7,7]
case 5
in: [[]]
expected: [0,0]
Starter codePython
def quartiles(data):
    # Your code here
    pass

5 test cases · run your code against them in the editor