-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathlo_shu.py
47 lines (34 loc) · 1.03 KB
/
lo_shu.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Mark Sherriff (mss2x)
numbers = (input("Numbers: ")).split()
square = [[0,0,0],[0,0,0],[0,0,0]]
count = 0
is_square = True
for i in range(3):
for j in range(3):
square[i][j] = int(numbers[count])
count += 1
# print(square)
print("You entered:")
for row in square:
print(str(row[0]) + '\t' + str(row[1]) + '\t' + str(row[2]))
# check rows
for row in square:
if sum(row) != 15:
is_square = False
print(str(row) + " fails the test!")
# check cols
for i in range(3):
if square[0][i] + square[1][i] + square[2][i] != 15:
is_square = False
print("Column " + str(i) + " fails the test!")
# check diagonals
if square[0][0] + square[1][1] + square[2][2] != 15:
is_square = False
print("Left->Right diagonal fails the test!")
if square[0][2] + square[1][1] + square[2][0] != 15:
is_square = False
print("Right->Left diagonal fails the test!")
if not is_square:
print("This is not a Lo Shu Magic Square!")
else:
print("This is a valid Lo Shu Magic Square!")