GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Beginner-Python-exercises/Exercise-24-Draw-A-Game-Board.py at master · ihossai4/Beginner-Python-exercises

Expand file tree

/

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

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
59 lines (47 loc) · 1.28 KB
/

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

Copy path

File metadata and controls

59 lines (47 loc) · 1.28 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
# --- --- --- ---
# | | | | |
# --- --- --- ---
# | | | | |
# --- --- --- ---
# | | | | |
# --- --- --- ---
# | | | | |
# --- --- --- ---
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.