For n independent Bernoulli trials with success probability p, compute the probability of exactly k successes:
P(X=k)=(kn)pk(1−p)n−kAlso compute the probability of at most k successes:
P(X≤k)=i=0∑k(in)pi(1−p)n−iHere, i is a possible success count. Return a dictionary containing pmf and cdf as Python floats.
Input: n = 5, p = 0.5, k = 2
Output: {"pmf": 0.3125, "cdf": 0.5}
Explanation: Exactly two successes has probability 0.3125, while zero through two successes sum to 0.5.
Input: n = 10, p = 0.3, k = 0
Output: {"pmf": 0.028248, "cdf": 0.028248}
Input: n = 8, p = 0.7, k = 8
Output: {"pmf": 0.057648, "cdf": 1.0}
Use math.comb(n, i) for each binomial coefficient.
Build probabilities for i from 0 through k, then use the last value as the PMF and their sum as the CDF.
Sign in to take notes on this problem
Accepts: number
Accepts: number
Accepts: number
For n independent Bernoulli trials with success probability p, compute the probability of exactly k successes:
P(X=k)=(kn)pk(1−p)n−kAlso compute the probability of at most k successes:
P(X≤k)=i=0∑k(in)pi(1−p)n−iHere, i is a possible success count. Return a dictionary containing pmf and cdf as Python floats.
Input: n = 5, p = 0.5, k = 2
Output: {"pmf": 0.3125, "cdf": 0.5}
Explanation: Exactly two successes has probability 0.3125, while zero through two successes sum to 0.5.
Input: n = 10, p = 0.3, k = 0
Output: {"pmf": 0.028248, "cdf": 0.028248}
Input: n = 8, p = 0.7, k = 8
Output: {"pmf": 0.057648, "cdf": 1.0}
Use math.comb(n, i) for each binomial coefficient.
Build probabilities for i from 0 through k, then use the last value as the PMF and their sum as the CDF.
Sign in to take notes on this problem
Accepts: number
Accepts: number
Accepts: number