Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

11. Lo Shu Magic Square The Lo Shu Magic is a grid with 3 rows and 3 columns, sh

ID: 3778420 • Letter: 1

Question

11. Lo Shu Magic Square The Lo Shu Magic is a grid with 3 rows and 3 columns, shown in Figure 7-8. The Shu Magic Square has the following properties: The grid contains the numbers 1 through 9 exactly. The sum of each row, each column, and each diagonal all add up to the same number. This is shown in Figure 7-9. In a program you can simulate a magic square using a two-dimensional list. Write a func- tion that accepts a two-dimensional list as an argument and determines whether the list is a Lo Shu Magic Square. Test the function in a program.

Explanation / Answer

def checkSquare(square,n):

        for x in square:

            for y in range(3):

                if sum(x) == sum (square[y][y] for y in range(3)):

                    if sum(x)== sum(x[y] for x in square):

                        checks1 = ' is a Lo Shu Magic Square'

                else:

                        checks1= ' is Not a Lo Shu Magic Square'

        print("Square",str(n), checks1)

        return None

    def main():

        square1 = [[8, 1, 6], [3, 5, 7], [4, 9, 2]]

        checkSquare(square1,1)

        square2 = [[8, 9, 6], [3, 1, 7], [4, 2, 5]]

        checkSquare(square2,2)

        square3 = [[9, 3, 6], [5, 1, 4], [2, 7, 8]]

        checkSquare(square3,3)

        square4 = [[4, 9, 2], [3, 5, 7], [8, 1, 6]]

        checkSquare(square4,4)

        square5 = [[5, 3, 8], [4, 2, 7], [6, 9, 1]]

        checkSquare(square5,5)

        square6 = [[5, 1, 7], [9, 4, 2], [6, 3, 8]]

        checkSquare(square6,6)

        square7 = [[7, 9, 6], [2, 3, 8], [5, 4, 1]]

        checkSquare(square7,7)

        square8 = [[8, 3, 4], [1, 5, 9], [6, 7, 2]]

        checkSquare(square8,8)

    main()

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote