Skip to content

Commit f441286

Browse files
author
Amogh Singhal
authored
Create binomialCoefficient.py
1 parent 5fc955c commit f441286

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

bits_wilp/binomialCoefficient.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
def factorial(n):
2+
if n < 2:
3+
return 1
4+
else:
5+
return n * factorial(n-1)
6+
7+
8+
n = int(input("Enter the value of n: "))
9+
r = int(input("Enter the value of r: "))
10+
11+
# int division to avoid `float` output
12+
ncr = factorial(n) // (factorial(r) * factorial(n-r))
13+
14+
# string formatting
15+
result = "The binomial coefficient for {n} and {r} is {ncr}".format(n=n, r=r, ncr=ncr)
16+
print(result)

0 commit comments

Comments
 (0)