human
Find two numbers from their sum and XOR | Set 2 | Function to find the value of A and B whose sum is X and xor is Y.
Initialize the two numbers.
Case 1 : X < Y.
Case 2 : X - Y is odd.
Case 3 : If both Sum and XOR are equal.
Case 4 : If above cases fails.
Update the value of A.
Check if A & Y value is 0.
If True , update B.
Otherwise assign - 1 to A , - 1 to B.
Prthe numbers A and B.
Driver Code.
Given Sum and XOR of 2 numbers.
Function Call"
How can the above be solved in Python?
assistant
#Here is code to find two numbers from their sum and XOR and the other steps required.
 def findNums ( X , Y ) :
	A = 0 ;
	B = 0 ;
	if ( X < Y ) :
		A = - 1 ;
		B = - 1 ;
	elif ( ( ( abs ( X - Y ) ) & 1 ) != 0 ) :
		A = - 1 ;
		B = - 1 ;
	elif ( X == Y ) :
		A = 0 ;
		B = Y ;
	else :
		A = ( X - Y ) // 2 ;
		if ( ( A & Y ) == 0 ) :
			B = ( A + Y ) ;
		else :
			A = - 1 ;
			B = - 1 ;
	print A ;
	print B ;
if __name__ == ' _ _ main _ _ ' :
	X = 17 ;
	Y = 13 ;
	findNums ( X , Y ) ;