-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathExercise-24-Draw-A-Game-Board.py
59 lines (47 loc) · 1.28 KB
/
Exercise-24-Draw-A-Game-Board.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
'''
Exercise 24: Draw A Game Board
This exercise is Part 1 of 4 of the Tic Tac Toe exercise series.
The other exercises are: Part 2, Part 3, and Part 4.
Time for some fake graphics! Let’s say we want to draw game boards
that look like this:
--- --- ---
| | | |
--- --- ---
| | | |
--- --- ---
| | | |
--- --- ---
This one is 3x3 (like in tic tac toe). Obviously, they come in many
other sizes (8x8 for chess, 19x19 for Go, and many more).
Ask the user what size game board they want to draw, and draw it
for them to the screen using Python’s print statement.
'''
# Solution
def draw_board(size):
"""
Draw game boards in size of 'size'.
Arguments:
size -- the size of the board.
"""
h_element = ' ---'
v_element = '| '
for i in range(size):
print(h_element * (size))
print(v_element * (size+1))
print(h_element * (size))
def main():
draw_board(int(input('Please input the size of board:')))
if __name__ == "__main__":
main()
# Test Part
# >>> %Run test.py
# Please input the size of board:4
# --- --- --- ---
# | | | | |
# --- --- --- ---
# | | | | |
# --- --- --- ---
# | | | | |
# --- --- --- ---
# | | | | |
# --- --- --- ---