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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started