> For the complete documentation index, see [llms.txt](https://stephanosterburg.gitbook.io/scrapbook/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://stephanosterburg.gitbook.io/scrapbook/math/hackerrank/binomial-distribution.md).

# 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


```
