-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtictactoe.py
More file actions
28 lines (22 loc) · 761 Bytes
/
tictactoe.py
File metadata and controls
28 lines (22 loc) · 761 Bytes
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
#!/usr/bin/python3
# game of tic tac toe for the command line
gameboard = {"top-l": " ", "top-m": " ", "top-r": " ",
"mid-l": " ", "mid-m": " ", "mid-r": " ",
"bot-l": " ", "bot-m": " ", "bot-r": " "}
def printToScreen(board):
print(board["top-l"] + "|" + board["top-m"] + "|" + board["top-r"])
print("-+-+-")
print(board["mid-l"] + "|" + board["mid-m"] + "|" + board["mid-r"])
print("-+-+-")
print(board["bot-l"] + "|" + board["bot-m"] + "|" + board["bot-r"])
turn = "X"
for i in range(9):
printToScreen(gameboard)
print("Turn for " + turn + ". Pick your move")
move = input()
gameboard[move] = turn
if turn == "X":
turn = "O"
else:
turn = "X"
printToScreen(gameboard)