In what concerns the continuous evaluation solving exercises grade during the semester, you should submit until 23:59 of November 8th
(this exercise will still be available for submission after that deadline, but without counting towards your grade)
[to understand the context of this problem, you should read the EDIT LINK TO NEW SHEET


In this problem you should submit a function as described. Inside the function do not print anything that was not asked!

The name of the .py source file you submit to Mooshak should NOT start with a digit (you will get an error if you submit it like that).

[IP054] Is it magical?

With all the Patty and Selma squabble, their mother Jacqueline recalled something she had not thought of in a long time: Mathematical Sorcery. “Good heavens! These matrices have become magical!”. After calming down with a good glass of wine and a smoke, she explained: when matrices have each row, column and diagonal sums being exactly the same, they reach their apex. We can use this to get all we ever want!!

The Problem

Write a function magical(mat) that given a square matrix mat (with the same number of columns as rows), checks if all columns, rows and diagonals (hint: recall that matrices have only two diagonals) sum to the same value. If so, return True, otherwise return False.

Constraints

The following limits are guaranteed in all the test cases that will be given to your program:

1 ≤ |mat| ≤ 10       Dimensions of the matrix

Example Function Calls Example Output
print(magical([[5, 1], [2, 0]]))
print(magical([[8, 1, 6], [3, 5, 7], [4, 9, 2]]))
False
True

Introduction to Programming (CC1024)
DCC/FCUP - University of Porto