human
Check if elements of a Binary Matrix can be made alternating | Function to create the possible grids.
Function to test if any one of them matches with the given 2 - D array.
Function to print the grid , if possible.
Function to check if the grid can be made alternating or not.
Grids to store the possible grids.
Driver Code"
How can the above be solved in Python?

Write me a code to check if elements of a Binary Matrix can be made alternating and the other steps required?
assistant
#Here is code to check if elements of a Binary Matrix can be made alternating and the other steps required.
 def createGrid ( grid , is1 , N , M ) :
	for i in range ( N ) :
		for j in range ( M ) :
			if ( is1 ) :
				grid [ i ] [ j ] = '0'
				is1 = False
			else :
				grid [ i ] [ j ] = '1'
				is1 = True
		if ( M % 2 == 0 ) :
			is1 = True if is1 == False else False
def testGrid ( testGrid , Grid , N , M ) :
	for i in range ( N ) :
		for j in range ( M ) :
			if ( Grid [ i ] [ j ] != ' * ' ) :
				if ( Grid [ i ] [ j ] != testGrid [ i ] [ j ] ) :
					return False
	return True
def printGrid ( grid , N , M ) :
	for i in range ( N ) :
		for j in range ( M ) :
			print ( grid [ i ] [ j ] , end = " ▁ " )
		print ( " " , end ▁ = ▁ " " )
def findPossibleGrid ( N , M , grid ) :
	gridTest1 = [ [ ' ' for i in range ( 1001 ) ] for j in range ( N ) ]
	gridTest2 = [ [ ' ' for i in range ( 1001 ) ] for j in range ( N ) ]
	createGrid ( gridTest1 , True , N , M )
	createGrid ( gridTest2 , False , N , M )
	if ( testGrid ( gridTest1 , grid , N , M ) ) :
		print ( " Yes " )
		printGrid ( gridTest1 , N , M )
	elif ( testGrid ( gridTest2 , grid , N , M ) ) :
		print ( " Yes " )
		printGrid ( gridTest2 , N , M )
	else :
		print ( " No " )
if __name__ == ' _ _ main _ _ ' :
	N = 4
	M = 4
	grid = [ [ ' * ' , ' * ' , '1' , '0' ] , [ ' * ' , ' * ' , ' * ' , ' * ' ] , [ ' * ' , ' * ' , ' * ' , ' * ' ] , [ ' * ' , ' * ' , '0' , '1' ] ]
	findPossibleGrid ( N , M , grid )