human
What is a code to number of Subsequences with Even and Odd Sum and the other steps required given the following:
Number of Subsequences with Even and Odd Sum | Set 2 | Function to find number of Subsequences with Even and Odd Sum.
Counting number of odds.
Even count.
Total Subsequences is ( 2 ^ n - 1 ) For NumberOfEvenSubsequences subtract NumberOfOddSubsequences from total.
Driver code.
Calling the function"
How can the above be solved in Python?
assistant
#Here is code to number of Subsequences with Even and Odd Sum and the other steps required.
 def countSum ( arr , n ) :
	NumberOfOdds = 0 ; NumberOfEvens = 0 ;
	for i in range ( n ) :
		if ( arr [ i ] & 1 ) :
			NumberOfOdds += 1 ;
	NumberOfEvens = n - NumberOfOdds ;
	NumberOfOddSubsequences = ( 1 << NumberOfEvens ) * ( 1 << ( NumberOfOdds - 1 ) ) ;
	NumberOfEvenSubsequences = ( 1 << n ) - 1 - NumberOfOddSubsequences ;
	return ( NumberOfEvenSubsequences , NumberOfOddSubsequences ) ;
if __name__ == " _ _ main _ _ " :
	arr = [ 1 , 2 , 2 , 3 ] ;
	n = len ( arr ) ;
	ans = countSum ( arr , n ) ;
	print ( " EvenSum ▁ = " , ans [ 0 ] , end = " ▁ " ) ;
	print ( " OddSum ▁ = " , ans [ 1 ] ) ;