Question: PYTHON 3: An n x n matrix forms a magic square if the following conditions are met: 1. The elements of the matrix are numbers
PYTHON 3:
An n x n matrix forms a magic square if the following conditions are met:
1. The elements of the matrix are numbers 1,2,3, ..., n2
2. The sum of the elements in each row, in each column and in the two diagonals is the same value.
Question: Complete the function that tets if the given matrix m forms a magic square.
def is_square(m): '''2d-list => bool Return True if m is a square matrix, otherwise return False (Matrix is square if it has the same number of rows and columns''' for i in range(len(m)): if len(m[i]) != len(m): return False return True
def magic(m): '''2D list->bool Returns True if m forms a magic square Precondition: m is a matrix with at least 2 rows and 2 columns '''
if(not(is_square(m))): return False
#and this is where I need help on what code can complete this
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
