-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTP_Exercise 3.16.py
More file actions
57 lines (43 loc) · 1.14 KB
/
Copy pathTP_Exercise 3.16.py
File metadata and controls
57 lines (43 loc) · 1.14 KB
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
"""
v1.2 11-19-20
My solution for the 3.16 working example in Chap. 3 of
Think Python by Allen Downey
I have improved on the challenge so that you can build
a grid of any size by adjusting the variables num_rows
and num_cols.
Code to build unit is now encapsulated for simplicity
I will add a user entry box in the code as the next task
"""
num_rows = 3
num_cols = 3
t_r = "+ - - - -" #single unit beam
m_r = "| " #single unit post
#function prints out
def unit_print(a,b):
for i in range(b):
print(a,end=' ')
#function prints a 'beam' row with num_cols*columns
def beam_print(arg):
unit_print(arg,num_cols)
print('+')
#
#function prints a 'post'row with num_cols*columns
def post_print(arg):
unit_print(arg,num_cols)
print("|")
#
#construct the middle of a block
def do_four(f,arg):
for i in range(4):
f(arg)
def print_unit():
beam_print(t_r)
do_four(post_print, m_r)
#
#builds a grid with num_rows*rows
def build_grid():
for i in range(num_rows):
print_unit()
beam_print(t_r)
#
build_grid()