human
Number of words that can be made using exactly P consonants and Q vowels from the given string | Function to return the value of nCk.
Function to return the factorial of n.
Function that returns true if ch is a vowel.
Function to return the number of words possible.
To store the count of vowels and consonanats in the given string.
If current character is a vowel.
Find the total possible words.
Driver code"
How can the above be solved in Python?
 Give me a code to number of words that can be made using exactly P consonants and Q vowels from the given string and the other steps required?
assistant
#Here is code to number of words that can be made using exactly P consonants and Q vowels from the given string and the other steps required.
 def binomialCoeff ( n , k ) :
	if ( k == 0 or k == n ) :
		return 1
	return binomialCoeff ( n - 1 , k - 1 ) + binomialCoeff ( n - 1 , k )
def fact ( n ) :
	if ( n >= 1 ) :
		return n * fact ( n - 1 )
	else :
		return 1
def isVowel ( ch ) :
	if ( ch == ' a ' or ch == ' e ' or ch == ' i ' or ch == ' o ' or ch == ' u ' ) :
		return True
	return False
def countWords ( s , p , q ) :
	countc = 0
	countv = 0
	for i in range ( len ( s ) ) :
		if ( isVowel ( s [ i ] ) ) :
			countv += 1
		else :
			countc += 1
	a = binomialCoeff ( countc , p )
	b = binomialCoeff ( countv , q )
	c = fact ( p + q )
	ans = ( a * b ) * c
	return ans
s = " crackathon "
p = 4
q = 3
print ( countWords ( s , p , q ) )