Write a python program that simulates a lo shu magic square using a two-dimensional list. The program should initialize a two-dimensional list with trial values. Don't ask for values as user input. Program must determine if the array is a Lo Shu Magic Square. These contain numbers 1-9 and have 3 rows and 3 columns. I want to use the following functions in the program: drawBoard(): No return value. Takes a two-dimensional list as input. Prints the Lo Shu Magic Square. isWinner(): Returns True when all the winning properties are satisfied. Takes a two-dimensional list as input. checkNumbers(): Returns True when the digits 1-9 exactly are used. Takes a two-dimensional list as input. checkRows(): Returns True when the sums of the rows are the same. Takes a two-dimensional list as input. checkColumns(): Returns True when the sums of the columns are the same. Takes a two-dimensional list as input. checkDiagonals(): Returns True when the sums of the diagonals are the same. Takes a two-dimensional list as input.
Write a python
drawBoard(): No return value. Takes a two-dimensional list as input.
Prints the Lo Shu Magic Square.
isWinner(): Returns True when all the winning properties are satisfied.
Takes a two-dimensional list as input.
checkNumbers(): Returns True when the digits 1-9 exactly are used.
Takes a two-dimensional list as input.
checkRows(): Returns True when the sums of the rows are the same.
Takes a two-dimensional list as input.
checkColumns(): Returns True when the sums of the columns are the same.
Takes a two-dimensional list as input.
checkDiagonals(): Returns True when the sums of the diagonals are the same.
Takes a two-dimensional list as input.
I will attach a picture of the code I've tried so far.
![**Chapter 8 Programming Activity 8: Lists and Dictionaries**
**Author:** Brielle Sindt
**Date:** 10-20-2023
### Overview
This code checks if a given 3x3 list of integers forms a Lo Shu Magic Square. A Lo Shu Magic Square is a grid with numbers 1 through 9 in which the sum of every row, column, and diagonal is 15.
### Constants
The script starts by defining some constants that might be used in the code:
- `#rows`
- `#columns`
- `#minimum`
- `#maximum`
- `#start_index`
- `#no_good`
### Process
The `drawBoard` variable takes input and converts it into a list of integers:
```python
drawBoard=[int(input('4, 9, 2, 3, 5, 7, 8, 1, 6'))]
```
### Functions
#### Printing the Square
The code iterates over the square to print each row for visualization.
```python
for row in square:
print(row)
```
#### LoShu Function
```python
def LoShu(List2d):
if isinstance(List2d, list) and len(List2d)==3:
List1d=sum(List2d,[])
print(List1d)
if max(List1d) <=10 or min(List1d) <=0:
print("No good")
return False
```
The `LoShu` function checks whether:
- The input is a list with three elements.
- The elements contain numbers between 1 and 9.
### Checking Rows, Columns, and Diagonals
#### Check Rows
Calculates the sum for each row:
```python
row1sum= List2d[0][0]+List2d[0][1]+List2d[0][2]
row2sum= List2d[1][0]+List2d[1][1]+List2d[1][2]
row3sum= List2d[2][0]+List2d[2][1]+List2d[2][2]
```
#### Check Columns
Calculates the sum for each column:
```python
col1sum= List1d[0]+List1d[3]+List1d[6]
col2sum= List1d[1](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F4fd19836-9b26-4543-9bb9-ab1bff952376%2F261147c4-63b0-4100-9169-7bc487842334%2Fo14yl2_processed.jpeg&w=3840&q=75)

Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 3 images









