Count and Print the alphabets having ASCII value not in the range [ l , r ] | Function to count the number of characters whose ascii value not in range [ l , r ] ; Initializing the count to 0 ; using map to pra character only once ; Increment the count if the value is less ; return the count ; Driver Code
def CountCharacters ( str , l , r ) : NEW_LINE INDENT cnt = 0 NEW_LINE m = { } NEW_LINE length = len ( str ) NEW_LINE for i in range ( 0 , length ) : NEW_LINE INDENT if ( not ( l <= ord ( str [ i ] ) and ord ( str [ i ] ) <= r ) ) : NEW_LINE INDENT cnt += 1 NEW_LINE if ord ( str [ i ] ) not in m : NEW_LINE INDENT m [ ord ( str [ i ] ) ] = 0 NEW_LINE print ( str [ i ] , end = " ▁ " ) NEW_LINE DEDENT m [ ord ( str [ i ] ) ] += 1 NEW_LINE DEDENT DEDENT return cnt NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT str = " geeksforgeeks " NEW_LINE str = str . strip ( ) NEW_LINE l = 102 NEW_LINE r = 111 NEW_LINE print ( " Characters ▁ with ▁ ASCII ▁ values " , end = " " ) NEW_LINE print ( " not in the range [ l , r ] " , ▁ " in the given string are : " , ▁ end ▁ = ▁ " " ) NEW_LINE print ( " and their count is   " , CountCharacters ( str , l , r ) ) NEW_LINE DEDENT