Skip to content

Commit b03e850

Browse files
committed
Week 1 Homework for Salim
1 parent 5bb813b commit b03e850

1 file changed

Lines changed: 74 additions & 0 deletions

File tree

‎Students/salim/draw_box.py‎

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
def print_grid(size, boxes):
2+
3+
# adjust wrong inputs
4+
size, boxes = adjust_inputs(size, boxes)
5+
6+
# rows of grid
7+
row_count = 0
8+
for i in range(size):
9+
10+
# if row is a solid line
11+
if row_count % (size / boxes) == 0:
12+
13+
print_row(width=size, row_type='solid', boxes=boxes)
14+
15+
# if row is a non-solid line
16+
else:
17+
18+
print_row(width=size, row_type='non-solid', boxes=boxes)
19+
20+
# increment row_count
21+
row_count += 1
22+
23+
24+
def print_row(width, row_type, boxes):
25+
26+
# set row type
27+
if row_type == 'solid':
28+
outside = '+'
29+
inside = '-'
30+
elif row_type == 'non-solid':
31+
outside = '|'
32+
inside = ' '
33+
34+
# columns of row
35+
col_count = 0
36+
for ii in range(width):
37+
38+
# if middle of row
39+
if col_count < (width - 1):
40+
41+
if col_count % (width / boxes) == 0:
42+
print outside, # include commas to keep text on same line
43+
else:
44+
print inside, # include commas to keep text on same line
45+
46+
# if end of row
47+
else:
48+
49+
if col_count % (width / boxes) == 0 or boxes == 1:
50+
print outside
51+
else:
52+
print inside
53+
54+
# increment col_count
55+
col_count += 1
56+
57+
58+
def adjust_inputs(size, boxes):
59+
60+
# if size input is even, change to next biggest odd number
61+
if size % 2 == 0:
62+
size_result = size + 1
63+
else:
64+
size_result = size
65+
66+
# min of boxes value 1 and boxes value not greater than size_result
67+
if boxes <= 1:
68+
boxes_result = 1
69+
elif boxes > size_result:
70+
boxes_result = size_result
71+
else:
72+
boxes_result = boxes
73+
74+
return size_result, boxes_result

0 commit comments

Comments
 (0)