Count consonants in a string ( Iterative and recursive methods ) | Function to check for consonant ; To handle lower case ; To check is character is Consonant ; 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 ) : NEW_LINE INDENT count = 0 NEW_LINE for i in range ( len ( string ) ) : NEW_LINE INDENT if ( isConsonant ( string [ i ] ) ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT return count NEW_LINE DEDENT string = " abc ▁ de " NEW_LINE print ( totalConsonants ( string ) ) NEW_LINE