Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

Marketing information and customer insights

Answered: 1 week ago