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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

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. 

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
Transcribed Image Text:**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
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Arrays
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education