Given an array A [ ] and a number x , check for pair in A [ ] with sum as x | Function to find and print pair ; Driver code
def chkPair ( A , size , x ) : NEW_LINE INDENT for i in range ( 0 , size - 1 ) : NEW_LINE INDENT for j in range ( i + 1 , size ) : NEW_LINE INDENT if ( A [ i ] + A [ j ] == x ) : NEW_LINE INDENT print ( " Pair ▁ with ▁ a ▁ given ▁ sum ▁ " , x , " ▁ is ▁ ( " , A [ i ] , " , ▁ " , A [ j ] , " ) " ) NEW_LINE return True NEW_LINE DEDENT DEDENT DEDENT return False NEW_LINE DEDENT A = [ 0 , - 1 , 2 , - 3 , 1 ] NEW_LINE x = - 2 NEW_LINE size = len ( A ) NEW_LINE if ( chkPair ( A , size , x ) ) : NEW_LINE INDENT print ( " Valid ▁ pair ▁ exists " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No ▁ valid ▁ pair ▁ exists ▁ for ▁ " , x ) NEW_LINE DEDENT