All problems
Cantelli Bound Value
Problem
Cantelli's one-sided inequality bounds P(X - mean >= a) by variance / (variance + a^2) for a > 0. Return the bound, 1.0 for a <= 0, and 0.0 when the variance is nonpositive.
Hint
The bound interpolates smoothly between 0 and 1 as a grows.
Test cases
case 1
in: [1,1]
expected: 0.5
case 2
in: [1,2]
expected: 0.2
case 3
in: [4,2]
expected: 0.5
case 4
in: [0,1]
expected: 0
case 5
in: [1,0]
expected: 1
Starter codePython
def cantelli_bound(variance, a):
# Your code here
pass5 test cases · run your code against them in the editor