-
Notifications
You must be signed in to change notification settings - Fork 2
Code the functions
Maciej Jankowski edited this page Jun 25, 2019
·
7 revisions
How do we draw the board?
for example:
X | X | X
--+---+--
O | O | X
--+---+--
O | X | O
You can see:
- value of each cell, separated by pipe symbol
- separating horizontal line
What our code should do:
- prepare text for every data line
- prepare text for separator line
- display prepared text on the screen
Now, in the first lines we should have:
def draw_board(cells):
# prepare output data
line_separator = "--+--+--"
line_1 = cells[0] + " | " + cells[1] + " | " + cells[2]
line_2 = cells[3] + " | " + cells[4] + " | " + cells[5]
line_3 = cells[6] + " | " + cells[7] + " | " + cells[8]
# print output data
print(line_1)
print(line_separator)
print(line_2)
print(line_separator)
print(line_3)
So you basically repeat the steps of breaking down the tasks until you know how to do them. That's the magic behind writing code :)