Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 1 : Magic Square ( 4 0 marks ) Write a program ( magic _ square.py ) that will read a sequence of values

Question 1: Magic Square (40 marks)
Write a program (magic_square.py) that will read a sequence of values from the user. The
values should consist of digits from the set {1,2,dots,9} and at most one 'x'. The program must
check if the 'x' could be replaced by a digit so that the numbers make a 3 by 3 magic square. If
there is no 'x', then it should check if the digits make a magic square. It will display the numbers
in a 3 by 3 matrix if possible. It will then inform the user if the matrix makes a magic square or
not. A magic square is a matrix of numbers where the sum in any direction is the same (rows,
columns, and diagonals), and the square contains the numbers from 1 to the number of squares
(in this case, the numbers 1 to 9, each one exactly once). Design and break down your program
into different functions.
See the output below as a guide. Your program must be consistent with the sample run. Note
that the digits may be unseparated, or they may be separated by any character that is not a digit
or an x.
Sample run 1:
-----Magic Square Checker-----
Please enter the numbers 1 through 9: 146??782,5
Numbers do not make a square of size 3!
Sample run 2:
-----Magic Square Checker-----
Please enter the numbers 1 through 9: 146,78 x 5
Numbers do not make a square of size 3!
Sample run 3:
Please enter the numbers 1 through 9: 276,9514-3-8
276
951
438
The square is magical!
Sample run 4:
-----Magic Square Checker-----
Please enter the numbers 1 through 9:276/91438
276
951
438
The square is magical!
Sample run 5:
-----Magic Square Checker-----
Please enter the numbers 1 through 9: 276,91435
276
91
435
using python
image text in transcribed

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

Fundamentals Of Database Systems

Authors: Sham Navathe,Ramez Elmasri

5th Edition

B01FGJTE0Q, 978-0805317558

More Books

Students also viewed these Databases questions

Question

Describe loss aversion and myopic loss aversion.

Answered: 1 week ago