Question

In: Computer Science

The Lo Shu Magic Square is a grid with 3 rows and 3 columns, shown in figure. The Lo Shu Magic Square has the following properties:

Python programming

The Lo Shu Magic Square is a grid with 3 rows and 3 columns, shown in figure. The Lo 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 as shown in figure.

In a program you can simulate a magic square using a two-dimensional list. Write a function that accepts a two-dimensional list as an argument and determines whether the list is a Lo Shu Magic Square. Tes the function in a program.

492
357
816

Solutions

Expert Solution

def checkLoShuMagicSquare(list):
COLUMNS = 3 # initialize column for 3*3 square
for row in list: #looping the list
for col in range (COLUMNS):
if sum(row) == sum (list[col][col] for col in range(COLUMNS)): #comparing the sum
if sum(row)== sum(row[col] for row in list): #comparing the sum
answer_output = str('This is a Lo Shu Magic Square')
else:
answer_output = str('This is not a Lo Shu Magic Square')

print(answer_output) #print the output

def main():
list = [[4,9,2], [3, 5, 7], [8,1,6]] #intialize alist
checkLoShuMagicSquare(list) #callig the function


main()

-------------------------------------------------output-----------------------------------------------------------

This is a Lo Shu Magic Square


Related Solutions

The Lo Shu Magic Square is a grid with 3 rows and 3 columns shown in...
The Lo Shu Magic Square is a grid with 3 rows and 3 columns shown in Figure 8-23. The Lo Shu Magic Square has the following properties: l The grid contains the numbers 1 through 9 exactly. l The sum of each row, each column, and each diagonal all add up to the same number. This is shown in Figure 8-24. In a program, you can simulate a magic square using a two-dimensional array. Design a program that initializes a...
Python: Lo Shu Magic Square The Lo Shu Magic Square is a grid with 3 rows...
Python: Lo Shu Magic Square The Lo Shu Magic Square is a grid with 3 rows and 3 columns, shown in figures below. The Lo 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 B. In a program you can stimulate a magic square using a two-dimensional list. Write a function...
1 How can we specify the number of rows and columns in a grid layout? 2....
1 How can we specify the number of rows and columns in a grid layout? 2. What happens when we don't have enough items to be displayed in a grid layout with a specified size? 3. How can we specify a grid layout component to occupy more than one columns or rows? 4. What happens if the components in a linear and grid layout exceed the layout size? How can we handle this problem so that all components can be...
Write a Python program which adds up columns and rows of given table as shown in...
Write a Python program which adds up columns and rows of given table as shown in the specified figure. Example test case (the four lines below “Input cell value” are input from user, and the five lines below “Results:” are the output of the program.): Input number of rows/columns (0 to exit) 4 Input cell value: 25 69 51 26 68 35 29 54 54 57 45 63 61 68 47 59 Result:             25   69   51   26 171...
Write a Python program which adds up columns and rows of given table as shown in...
Write a Python program which adds up columns and rows of given table as shown in the specified figure. Example test case (the four lines below “Input cell value” are input from user, and the five lines below “Results:” are the output of the program.): Input number of rows/columns (0 to exit) 4 Input cell value: 25 69 51 26 68 35 29 54 54 57 45 63 61 68 47 59 Result: 25 69 51 26 171 68 35...
1: A square footing is to be constructed as shown in the Figure at a founding...
1: A square footing is to be constructed as shown in the Figure at a founding depth of 2 m. Using the Terzaghi equation compute the ultimate surface capacity, [ (qult)Surf ], possible for the layered soil profile shown. Keeping in mind that Terzaghi’s semi-empirical bearing capacity equation can only be applied to a soil layer with a thickness greater than or equal to the applied stress contact-area-breadth (either virtual or real breadth). In such a case, second layer cannot...
/*Question 3: The following data contains five columns (variables) and five rows (observations). First, read the...
/*Question 3: The following data contains five columns (variables) and five rows (observations). First, read the data into SAS to create a data set. Notice that the first, third, and the fifth variable have missing values. Please replace the missing values of the first, third, and fifth variable with 30, 40, and 50, respectively. Next, for all the variables, if a value is at least 100, make an adjustment to the value such that its new value is equal to...
Write a script to display the following patterns on the screen. Number of rows and columns...
Write a script to display the following patterns on the screen. Number of rows and columns are taken from the command arguments; if they are missing, set default to 3 (rows) and 4 (columns). Hint: you will use a nested loop. **** **** **** a) Display the source code in an editor (#4-11) b) Execute your script in the terminal, and display the command and the result (#4-12)
Consider the following game. Ann chooses rows, and Bob chooses columns. [12 marks] LMR 3 4...
Consider the following game. Ann chooses rows, and Bob chooses columns. [12 marks] LMR 3 4 2 0 1 3 3 2 4 4 4 0 0 2 1 1 0 1 U C D (a) Find all pure strategy Nash Equilibria. (b) Find the set of Rationalizable strategies for each player. Find a dominating strategy for each deletion. (c) Is there a Nash equilibrium in which Bob puts strictly positive probability on L and M but none on R?...
The right half of the square loop of wire shown in Figure P24.37
The right half of the square loop of wire shown in Figure P24.37  is in a 0.85 T magnetic field directed into the page. The current in the loop is  1.3 A in a clockwise direction. What is the magnitude of the force on the loop, and in which direction does it act?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT