Reference no: EM132222085
Question 1:
Purpose: To build a program and test it. To get warmed up with Python, in case you are using it for the rst time.
A Magic Square is an arrangement of numbers in a square, so that every row, column, and diagonal add up to the same value. Below are two squares, but only one of them is a Magic Square.
8 1 6
3 5 7
4 9 2
1 9 6
5 3 7
4 8 2
The square on the left is a 3 3 magic square, whose rows, columns, and diagonals all sum to 15. On the right, is a 3 3 square of numbers whose rows columns and diagonals don't have the same sum.
There are magic squares of all sizes (except 22), but we'll be concerned with 33 squares, and checking if a given arrangement of 9 numbers is a magic square or not.
Denition: A 3 3 magic square is formally dened by the following three criteria:
It contains the integers 1 through 9 inclusively.
Every integer in the range 1 through 9 appears exactly once.
Every row, column, and diagonal sums to 15.
In this question you will implement a program that does the following:
It asks the user for a sequence of 9 numbers from the console. The order of the numbers is important, as the rows of the grid use this order. For simplicity, assume that the user will type integers on the console. For this question, you don't have worry about what to do if the user types anything other than integers.
It checks whether the sequence of integers is a magic square or not. Your program should display the message "yes" if it's magic, or "no" if it's not.
It's very important to point out that you are not being asked to construct a magic square; only to check if a square is magic or not.