In Python
Styles
1. Lo Shu Magic Square
The Lo Shu Magic Square is a grid with 3 rows and 3 columns shown in Figure 8-23. The Lo Shu Magic Square has the following properties:
4 9 2
3 5 7
8 1 6
Figure 8-23: Lo Shu Magic Square
The grid contains the numbers 1 through 9 exactly. The sum of each row, each column, and each diagonal all add up to the same number. This is shown in Figure 8-24.
5
I
3 5
15
8 -15
Figure 8-24: Row, column, and diagonal sums in the Lo Shu Magic Square
15 15 15 15
In a program, you can simulate a magic square using a two-dimensional array. Design a program that initializes a two-dimensional array with values entered by the user. The program should determine whether the array is a Lo Shu Magic Square. The program should verify user input is between 1 - 9. The program should print out the user input Square.