You are viewing a single comment's thread. Return to all comments →
from math import factorial as fact
def permutation(n, r): return fact(n)/(fact(n-r))
def combination(n, r): return permutation(n,r)/fact(r)
def binomial_dist(n, x, p):
q = 1-p
return combination(n, x)*(p**x)(q*(n-x))
you do the rest. :)
p = 0.12 n = 10 q1 = sum([binomial_dist(n, x, p) for x in range(0, 3)]) q2 = sum([binomial_dist(n, x, p) for x in range(2, 11)])
print(round(q1, 3)) print(round(q2, 3))
Seems like cookies are disabled on this browser, please enable them to open this website
I agree to HackerRank's Terms of Service and Privacy Policy.
Binomial Distribution #3
You are viewing a single comment's thread. Return to all comments →
from math import factorial as fact
Permutation
def permutation(n, r): return fact(n)/(fact(n-r))
Combinations
def combination(n, r): return permutation(n,r)/fact(r)
BINOMIAL DISTRIBUTION
def binomial_dist(n, x, p):
q = 1-p
return combination(n, x)*(p**x)(q*(n-x))
you do the rest. :)
p = 0.12 n = 10 q1 = sum([binomial_dist(n, x, p) for x in range(0, 3)]) q2 = sum([binomial_dist(n, x, p) for x in range(2, 11)])
print(round(q1, 3)) print(round(q2, 3))