All problems
Binomial CDF
Problem
Binomial cumulative distribution function P(X <= k) for n trials and success probability p.
Sum C(n, i) * p^i * (1 - p)^(n - i) for i from 0 to k. Return 0.0 for k < 0 and 1.0 for k >= n.
Hint
Sum the pmf terms from i = 0 through k.
Test cases
case 1
in: [10,0.5,5]
expected: 0.623046875
case 2
in: [10,0.5,0]
expected: 0.0009765625
case 3
in: [10,0.5,9]
expected: 0.9990234375
case 4
in: [5,0.2,-1]
expected: 0
case 5
in: [5,0.2,5]
expected: 1
Starter codePython
import math
def binomial_cdf(n, p, k):
# Your code here
pass5 test cases · run your code against them in the editor