Binomial Distribution

def factorial(n):
    if n == 0:
        return 1
    else:
        return n * factorial(n-1)


def dist(n, x):
    return factorial(n) / (factorial(x) * factorial(n-x))

def b(x, n, p):
    return dist(n, x) * p**x * (1-p)**(n-x)

#l, r = list(map(float, input().split(" ")))
ratio = 12/100

print(round(sum([b(i, 10, ratio) for i in range(0, 3)]), 3))  # 0.891
print(round(sum([b(i, 10, ratio) for i in range(2, 11)]), 3))  # 0.342

Last updated