Count consonants in a string ( Iterative and recursive methods ) | Function to check for consonant ; To handle lower case ; To count total number of consonants from 0 to n - 1 ; Driver code
def isConsonant ( ch ) : NEW_LINE INDENT ch = ch . upper ( ) NEW_LINE return not ( ch == ' A ' or ch == ' E ' or ch == ' I ' or ch == ' O ' or ch == ' U ' ) and ord ( ch ) >= 65 and ord ( ch ) <= 90 NEW_LINE DEDENT def totalConsonants ( string , n ) : NEW_LINE INDENT if n == 1 : NEW_LINE INDENT return isConsonant ( string [ 0 ] ) NEW_LINE DEDENT return totalConsonants ( string , n - 1 ) + isConsonant ( string [ n - 1 ] ) NEW_LINE DEDENT string = " abc ▁ de " NEW_LINE print ( totalConsonants ( string , len ( string ) ) ) NEW_LINE