-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtkpoint.py
More file actions
53 lines (46 loc) · 1.46 KB
/
tkpoint.py
File metadata and controls
53 lines (46 loc) · 1.46 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
41
42
43
44
45
46
47
48
49
50
theBoard = {"topL":" ","topM":" ","topR":" ",
"midL":" ","midM":" ","midR":" ",
"botL":" ","botM":" ","botR":" "}
def printBoard(board):
print(board["topL"]+'|'+board["topM"]+'|'+board["topR"])
print("-+-+-")
print(f'{board["midL"]}|{board["midM"]}|{board["midR"]}')
print("-+-+-")
print("{0}|{1}|{2}".format(board["botL"],board["botM"],board["botR"]))
printBoard(theBoard)
def NumtoBoard(num):
ls = ["topL","topM","topR",
"midL","midM","midR",
"botL","botM","botR"]
return ls[num - 1]
def validInput(input):
try:
temp = int(input)
return True
except:
return False
turn = "X"
for i in range(9):
printBoard(theBoard)
print(f'Turn for{turn},Move on which space?')
move = input(">> ")
#if(move != "X"||move != "O"):
while True:
if not validInput(move):
print(f'Turn for {turn}. move on which space?')
move = input(">> ")
if int(move) > 0 and int(move) < 10:
if theBoard[NumtoBoard(int(move))] == ' ':
break
else:
print(f'Invalid movement.Turn for {turn} . Move on which space?')
move = input(">> ")
else:
print(f"Invalid movement.Turn for {turn} . Move on which space?")
move = input (">> ")
theBoard[NumtoBoard(int (move))] = turn
if turn == 'X':
turn = 'O'
else:
turn = "X"
printBoard(theBoard)