human
Give me a code to arrangement of words without changing the relative position of vowel and consonants and the other steps required given the following:
Arrangement of words without changing the relative position of vowel and consonants | this function return n !.
this will return total number of ways.
freq maintains frequency of each character in word.
check character is vowel or not.
the characters that are not vowel must be consonant.
number of ways to arrange vowel.
multiply both as these are independent.
string contains only capital letters.
this will contain ans"
How can the above be solved in Python?
assistant
#Here is code to arrangement of words without changing the relative position of vowel and consonants and the other steps required.
 def factorial ( n ) :
	res = 1
	for i in range ( 1 , n + 1 ) :
		res = res * i
	return res
def count ( word ) :
	freq = [ 0 for i in range ( 30 ) ]
	vowel = 0
	consonant = 0
	for i in range ( len ( word ) ) :
		freq [ ord ( word [ i ] ) - 65 ] += 1
		if ( word [ i ] == ' A ' or word [ i ] == ' E ' or word [ i ] == ' I ' or word [ i ] == ' O ' or word [ i ] == ' U ' ) :
			vowel += 1
		else :
			consonant += 1
	vowelArrange = factorial ( vowel )
	vowelArrange //= factorial ( freq [ 0 ] )
	vowelArrange //= factorial ( freq [ 4 ] )
	vowelArrange //= factorial ( freq [ 8 ] )
	vowelArrange //= factorial ( freq [ 14 ] )
	vowelArrange //= factorial ( freq [ 20 ] )
	consonantArrange = factorial ( consonant )
	for i in range ( 26 ) :
		if ( i != 0 and i != 4 and i != 8 and i != 14 and i != 20 ) :
			consonantArrange //= factorial ( freq [ i ] )
	total = vowelArrange * consonantArrange
	return total
word = " COMPUTER "
ans = count ( word )
print ( ans )