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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!