We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
no_more_than_2 = sum(binomial_prob(n,k,p) for k in range(0, 3))
atleast_2 = sum(binomial_prob(n,k,p) for k in range(2, 11))
print(f"{no_more_than_2}:.3f")
print(f"{atleast_2}:.3f")
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Day 4: Binomial Distribution II
You are viewing a single comment's thread. Return to all comments →
Why this does not work? import math
def binomial_prob(n, k, p): return math.comb(n, k) * (p ** k) * ((1 - p) ** (n - k))
n = 10 p = 0.12
no_more_than_2 = sum(binomial_prob(n,k,p) for k in range(0, 3)) atleast_2 = sum(binomial_prob(n,k,p) for k in range(2, 11)) print(f"{no_more_than_2}:.3f") print(f"{atleast_2}:.3f")