Skip to content
DeepForgeby svx
All problems
EasyStatisticsst-143

Percentile Rank

Problem

Return the mid-rank percentile of value within scores: 100 * (count(scores < value) + 0.5 * count(scores == value)) / n. Half of the tied scores count as below, so the maximum of a distribution with ties does not automatically score 100. Return 0.0 for empty input.

Hint

The mid-rank convention gives tied scores half credit.

Test cases

case 1
in: [[1,2,3,4],2.5]
expected: 50
case 2
in: [[1,2,2,3],2]
expected: 50
case 3
in: [[1,2,3,4],4]
expected: 87.5
case 4
in: [[5,5,5],5]
expected: 50
case 5
in: [[1,2,3,4],0]
expected: 0
Starter codePython
def percentile_rank(scores, value):
    # Your code here
    pass

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