Skip to content
DeepForgeby svx
All problems
EasyStatisticsst-017

Interquartile Range

Problem

Return the interquartile range Q3 - Q1 using the exclusive method: sort the data, split it into lower and upper halves, and exclude the median from both halves when n is odd. Requires at least two values, otherwise return 0.0.

Hint

Q3 minus Q1, using the median of each half.

Test cases

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

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