human
Can you provide a code to find a Square Matrix such that sum of elements in every row and column is K and the other steps required given the following:
Find a Square Matrix such that sum of elements in every row and column is K | Function to print the required matrix.
Print k for the left diagonal elements.
Print 0 for the rest.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to find a Square Matrix such that sum of elements in every row and column is K and the other steps required.
 def printMatrix ( n , k ) :
	for i in range ( n ) :
		for j in range ( n ) :
			if ( i == j ) :
				print ( k , end = " ▁ " ) ;
			else :
				print ( "0" , end = " ▁ " ) ;
		print ( ) ;
if __name__ == " _ _ main _ _ " :
	n = 3 ; k = 7 ;
	printMatrix ( n , k ) ;