-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcountingwords.py
More file actions
35 lines (30 loc) · 809 Bytes
/
countingwords.py
File metadata and controls
35 lines (30 loc) · 809 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Python 3 program to find the number of words
# of X vowels and Y consonants can be
# formed from M vowels and N consonants
# Function to returns factorial of n
def fact(n):
res = 1
for i in range(2, n + 1, 1):
res = res * i
return res
# Function to find nCr
def nCr(n, r):
return fact(n) // (fact(r) * fact(n - r))
# Function to find the number of words
# of X vowels and Y consonants can be
# formed from M vowels and N consonants
def NumberOfWays(X, Y, M, N):
return fact(X + Y) * nCr(M, X) * nCr(N, Y)
# Driver code
if __name__ == '__main__':
X = 1
Y = 1
M = 5
N = 21
#If n is given. and x>1 & y=n-1
n=2
while(X<=n):
Y=n-X
X+=1
# Function call
print(NumberOfWays(X, Y, M, N))