Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Needs to be in Python 3! The Lo Shu Magic Square is a 3 by 3 grid with the following properties: The grid contains the

Needs to be in Python 3!

The Lo Shu Magic Square is a 3 by 3 grid with the following properties:

The grid contains the numbers 1 through 9 where each number appears exactly once in the grid.

The sum of each row, each column, and each diagonal all add up to the same number, 15

In a program, you can simulate a magic square by using a two-dimensional list. Write a Python program that tests whether or not a 3 by 3 grid is a valid magic square. The program reads the input from a text file named input.txt. Each line in the file contains exactly 9 numbers that correspond to the values in a possible magic square. The first three numbers correspond to the values in the first row, the next three values correspond to the second row, and the last three values correspond to the last row.

The text file looks like this:

4 3 8 9 5 1 2 7 6

8 3 4 1 5 9 6 7 2

6 1 8 7 5 3 2 9 4

6 9 8 7 5 3 2 1 4

6 1 8 7 5 3 2 1 4

6 1 3 2 9 4 8 7 5

5 5 5 5 5 5 5 5 5

This is the code I have so far:

def getMatrix (Empt): for line in open ("text1.txt", "r"): lst = line.split() for rowIndex in range(len(lst)): lst[rowIndex] = float(lst[rowIndex]) Empt.append([lst[0:3], lst[3:6], lst[6:9]]) return(Empt)

def main(): Empt = []

for row in Empt: Empt.append([0]* column) d = getMatrix (Empt) print (d)

main()

I'm a little confused where to go from here and am new to programming. Please help!

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

Practical Oracle8I Building Efficient Databases

Authors: Jonathan Lewis

1st Edition

0201715848, 978-0201715842

More Books

Students also viewed these Databases questions