Question
A python program A square array of numbers, usually positive integers, is called a magic square if the sums of the numbers in each row,
A python program
A square array of numbers, usually positive integers, is called a magic square if the sums of the numbers in each row, each column, and both main diagonals are the same. For example, in the following magic square the sum of each row, column, and both main diagonals is equal to 15:
In the module question4.py, create some functions that lets a caller determine if a two-dimensional array of integer values is or is not a magic square.
There must be one function named:
def is_magic(t):
where t is a two-dimensional array (list of lists) of integer values that returns True if t represents a magic square, and False otherwise. The function should not modify the array t.
You should decompose the problem down into separate functions rather than trying to solve the problem all in a single function. A sensible decomposition of the problem into separate functions contributes to your mark for this question.
A user of the module would call your is_magic function like so for the magic square shown above:
t = [[2, 7, 6], [9, 5, 1], [4, 3, 8]] boo = question4.is_magic(t)
Here are some more magic squares for testing purposes:
t = [[8, 1, 6], [3, 5, 7], [4, 9, 2]] t = [[2, 16, 13, 3], [11, 5, 8, 10], [7, 9, 12, 6], [14, 4, 1, 15]] t = [[1, 14, 4, 15], [8, 11, 5, 10], [13, 2, 16, 3], [12, 7, 9, 6]]
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