human
Character pairs from two strings with even sum | Function to return the total number of valid pairs.
Count total number of even and odd ascii values for string s1.
Count total number of even and odd ascii values for string s2.
Return total valid pairs.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to character pairs from two strings with even sum and the other steps required.
 def totalPairs ( s1 , s2 ) :
	a1 = 0 ; b1 = 0 ;
	for i in range ( len ( s1 ) ) :
		if ( ord ( s1 [ i ] ) % 2 != 0 ) :
			a1 += 1 ;
		else :
			b1 += 1 ;
	a2 = 0 ; b2 = 0 ;
	for i in range ( len ( s2 ) ) :
		if ( ord ( s2 [ i ] ) % 2 != 0 ) :
			a2 += 1 ;
		else :
			b2 += 1 ;
	return ( ( a1 * a2 ) + ( b1 * b2 ) ) ;
if __name__ == " _ _ main _ _ " :
	s1 = " geeks " ;
	s2 = " for " ;
	print ( totalPairs ( s1 , s2 ) ) ;