blob: b35a0d0a8dba9072e98db73351cf102a539b6ea2 (
plain)
1
2
3
4
5
6
7
8
9
10
|
def nCr(n, r):
if (r > n / 2):
r = n - r
answer = 1
for i in range(1, r + 1):
answer *= (n - r + i)
answer /= i
return answer
def binomial_probability(n, k, p):
return (nCr(n, k) * pow(p, k) * pow(1 - p, n - k))
|