-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLatin_Square.py
More file actions
40 lines (36 loc) · 1.05 KB
/
Latin_Square.py
File metadata and controls
40 lines (36 loc) · 1.05 KB
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
squareSize = ""
firstNum = ""
def again():
ans = input("Do you want to go again? (Y/N): ")
if (ans.lower() == "y" or ans.lower() == "yes"):
main()
return
def main():
while True:
squareSize = input("Please specify the size of the Square (1-9): ")
if (squareSize.isdigit()):
squareSize = int(squareSize)
if (squareSize > 9 or squareSize < 1):
print("This size is out of the acceptable range.")
else: break
else: print ("That is not a number.")
while True:
firstNum = input("Please specify the top left number of the Square: ")
if (firstNum.isdigit()):
firstNum = int(firstNum)
if (squareSize >= firstNum and firstNum >= 1): break
else: print (str(firstNum) + " is not in range of the Square.")
else: print(firstNum + " is not a number.")
for i in range(squareSize):
line = ""
nums = [j for j in range (firstNum, squareSize+1)]
if firstNum != 1:
nums += [j for j in range (1, firstNum)]
firstNum += 1
if (firstNum > squareSize):
firstNum = 1
for num in nums:
line += str(num)
print (line)
again()
main()