human
Find any possible two coordinates of Rectangle whose two coordinates are given | Function to find the remaining two rectangle coordinates.
Pairs to store the position of given two coordinates of the rectangle ..
Pairs to store the remaining two coordinates of the rectangle ..
Traverse through matrix and find pairs p1 and p2.
First Case.
Second Case.
Third Case.
Print the matrix.
Driver code.
Given Input.
Function Call"
How can the above be solved in Python?
assistant
#Here is code to find any possible two coordinates of Rectangle whose two coordinates are given and the other steps required.
 def Create_Rectangle ( arr , n ) :
	for i in range ( n ) :
		arr [ i ] = [ i for i in arr [ i ] ]
	p1 = [ - 1 , - 1 ]
	p2 = [ - 1 , - 1 ]
	p3 = [ ]
	p4 = [ ]
	for i in range ( n ) :
		for j in range ( n ) :
			if ( arr [ i ] [ j ] == '1' ) :
				if ( p1 [ 0 ] == - 1 ) :
					p1 = [ i , j ]
				else :
					p2 = [ i , j ]
	p3 = p1
	p4 = p2
	if ( p1 [ 0 ] == p2 [ 0 ] ) :
		p3 [ 0 ] = ( p1 [ 0 ] + 1 ) % n
		p4 [ 0 ] = ( p2 [ 0 ] + 1 ) % n
	elif ( p1 [ 1 ] == p2 [ 1 ] ) :
		p3 [ 1 ] = ( p1 [ 1 ] + 1 ) % n
		p4 [ 1 ] = ( p2 [ 1 ] + 1 ) % n
	else :
		p3 [ 0 ] , p4 [ 0 ] = p4 [ 0 ] , p3 [ 0 ]
	arr [ p3 [ 0 ] ] [ p3 [ 1 ] ] = '1'
	arr [ p4 [ 0 ] ] [ p4 [ 1 ] ] = '1'
	for i in range ( n ) :
		print ( " " . join ( arr [ i ] ) )
if __name__ == ' _ _ main _ _ ' :
	n = 4
	arr = [ "0010" , "0000" , "1000" , "0000" ]
	Create_Rectangle ( arr , n )