-
Notifications
You must be signed in to change notification settings - Fork 9
/
ex_03_5.py
65 lines (54 loc) · 1.53 KB
/
ex_03_5.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
60
61
62
63
64
65
#!/usr/bin/python
#AUTHOR: alexxa
#DATE: 24.12.2013
#SOURCE: Think Python: How to Think Like a Computer Scientist by Allen B. Downey
# http://www.greenteapress.com/thinkpython/html/index.html
#PURPOSE: Chapter 3. Functions
# Exercise 3.5
# This exercise can be done using only the statements and other
# features we have learned so far.
# 1. Write a function that draws a grid like the following:
# + - - - - + - - - - +
# | | |
# | | |
# | | |
# | | |
# + - - - - + - - - - +
# | | |
# | | |
# | | |
# | | |
# + - - - - + - - - - +
# 2. Write a function that draws a similar grid with four rows and
# four columns.
# My solution works for any number of rows and columns
def print_straight_slash_line(lines):
print(lines)
print(lines)
print(lines)
print(lines)
def grid_plus_line(num_of_columns):
columns = (' + - - - -')*num_of_columns + ' +'
print(columns)
def grid_row(num_of_columns):
grid_plus_line(num_of_columns)
lines = (' | ')*num_of_columns + ' |'
print_straight_slash_line(lines)
def grid_rows(num_of_rows, num_of_columns):
while num_of_rows > 1:
grid_row(num_of_columns)
num_of_rows -=1
def grid(num_of_rows, num_of_columns):
grid_row(num_of_columns)
grid_rows(num_of_rows, num_of_columns)
grid_plus_line(num_of_columns)
grid(1,1)
print()
grid(2,2)
print()
grid(8,8)
print()
grid(1,8)
print()
grid(8,1)
#END