Count strings with consonants and vowels at alternate position | Function to find the count of strings ; Variable to store the final result ; Loop iterating through string ; If ' $ ' is present at the even position in the string ; ' sum ' is multiplied by 21 ; If ' $ ' is present at the odd position in the string ; ' sum ' is multiplied by 5 ; Driver code ; Let the string ' str ' be s$$e$ ; Print result
def countStrings ( s ) : NEW_LINE INDENT sum = 1 NEW_LINE for i in range ( len ( s ) ) : NEW_LINE INDENT if ( i % 2 == 0 and s [ i ] == ' $ ' ) : NEW_LINE INDENT sum *= 21 NEW_LINE DEDENT elif ( s [ i ] == ' $ ' ) : NEW_LINE INDENT sum *= 5 NEW_LINE DEDENT DEDENT return sum NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT str = " s $ $ e $ " NEW_LINE print ( countStrings ( str ) ) NEW_LINE DEDENT