Question
I tried this code for my first attempt, however, it doesn't print the correct True or False response: def Sq_magic(inp): size = len(inp[0]) lst =
I tried this code for my first attempt, however, it doesn't print the correct True or False response:
def Sq_magic(inp):
size = len(inp[0])
lst = []
for c in range(size):
lst.append(sum(r[c] for r in inp))
lst.extend([sum (lines) for lines in inp])
rst = 0
for i in range(0,size):
rst +=inp[i][i]
lst.append(rst)
d_rst = 0
for i in range(size-1,-1,-1):
d_rst +=inp[i][i]
lst.append(d_rst)
if len(set(lst))>1:
return False
return True
print(Sq_magic([[4,9,2], [3,5,7], [8,1,6]]))
print(Sq_magic([[2,7,6], [9,5,1], [4,3,8]]))
print(Sq_magic([[1,2,3], [4,5,6], [7,8,9]]))
print(Sq_magic([[4,9,2], [3,5,5], [8,1,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