Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1cb795b

Browse files
authored
Create Exercise-24-Draw-A-Game-Board.py
1 parent 70fa918 commit 1cb795b

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

‎Exercise-24-Draw-A-Game-Board.py‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
'''
2+
Exercise 24: Draw A Game Board
3+
4+
This exercise is Part 1 of 4 of the Tic Tac Toe exercise series.
5+
The other exercises are: Part 2, Part 3, and Part 4.
6+
7+
Time for some fake graphics! Let’s say we want to draw game boards
8+
that look like this:
9+
10+
--- --- ---
11+
| | | |
12+
--- --- ---
13+
| | | |
14+
--- --- ---
15+
| | | |
16+
--- --- ---
17+
This one is 3x3 (like in tic tac toe). Obviously, they come in many
18+
other sizes (8x8 for chess, 19x19 for Go, and many more).
19+
20+
Ask the user what size game board they want to draw, and draw it
21+
for them to the screen using Python’s print statement.
22+
23+
'''
24+
25+
# Solution
26+
def draw_board(size):
27+
"""
28+
Draw game boards in size of 'size'.
29+
30+
Arguments:
31+
size -- the size of the board.
32+
33+
"""
34+
h_element = ' ---'
35+
v_element = '| '
36+
for i in range(size):
37+
print(h_element * (size))
38+
print(v_element * (size+1))
39+
print(h_element * (size))
40+
41+
42+
def main():
43+
draw_board(int(input('Please input the size of board:')))
44+
45+
if __name__ == "__main__":
46+
main()
47+
48+
# Test Part
49+
# >>> %Run test.py
50+
# Please input the size of board:4
51+
# --- --- --- ---
52+
# | | | | |
53+
# --- --- --- ---
54+
# | | | | |
55+
# --- --- --- ---
56+
# | | | | |
57+
# --- --- --- ---
58+
# | | | | |
59+
# --- --- --- ---

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /