Skip to content

Commit bc32ca9

Browse files
authored
Merge pull request UWPCE-PythonCert#81 from kathrynegan/master
Session03 and 04 activities
2 parents 41168e7 + d3770e3 commit bc32ca9

25 files changed

Lines changed: 347098 additions & 18 deletions

‎students/kegan/session02/print_grid.py‎

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,38 +16,62 @@
1616
def main():
1717
parser = argparse.ArgumentParser()
1818
parser.add_argument(
19-
'row', help='number of rows to print between 1 and 10',
19+
'rows', help='number of rows to print between 1 and 10',
2020
type=int, choices=range(1, 11))
2121
parser.add_argument(
22-
'column', help='number of columns to print between 1 and 10',
22+
'columns', help='number of columns to print between 1 and 10',
2323
type=int, choices=range(1, 11))
2424
args = parser.parse_args()
25-
# print row by column grid
26-
for i in range(args.row):
27-
print_horizontal(args.column)
28-
for i in range(4):
29-
print_vertical(args.column)
30-
print_horizontal(args.column)
25+
grid = build_grid(args.rows, args.columns)
26+
print(grid)
3127

3228

33-
def print_horizontal(column):
34-
""" Prints a horizontal component of grid."""
29+
def build_grid(rows, columns):
30+
""" Builds row x column grid.
31+
Args:
32+
rows (int) : number of rows
33+
columns (int) : number of columns
34+
Returns:
35+
str : row x column grid
36+
"""
37+
grid = []
38+
for __ in range(rows):
39+
grid.append(print_horizontal(columns))
40+
for __ in range(4):
41+
grid.append(print_vertical(columns))
42+
grid.append(print_horizontal(columns))
43+
grid = '\n'.join(grid)
44+
return grid
45+
46+
47+
def print_horizontal(columns):
48+
""" Returns a horizontal component of grid.
49+
Args:
50+
columns (int) : number of columns
51+
Returns;
52+
str : horizontal component of grid
53+
"""
3554
string = '*'
36-
for i in range(column):
37-
for i in range(4):
55+
for __ in range(columns):
56+
for __ in range(4):
3857
string += ' -'
3958
string += ' *'
40-
print(string)
59+
return string
4160

4261

43-
def print_vertical(column):
44-
""" Prints a vertical component of grid."""
62+
def print_vertical(columns):
63+
""" Returns a vertical component of grid.
64+
Args:
65+
columns (int) : number of columns
66+
Returns;
67+
str : vertical component of grid
68+
"""
4569
string = '|'
46-
for i in range(column):
47-
for i in range(9):
70+
for __ in range(columns):
71+
for __ in range(9):
4872
string += ' '
4973
string += '|'
50-
print(string)
74+
return string
5175

5276

5377
if __name__ == '__main__':
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2017 10 17 Session 03
2+
3+
Separation of Concerns: better to have a module produce content that is returned to a higher level function than to output that content itself
4+
5+
Interning: python uses the same id for integers through about 300
6+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Dear Benedict Cumberbatch,
2+
Thank you for your generous gift of $200,000. Your donation will go towards feeding homeless kittens in Seattle. From the bottom of our hearts, we at Miuvenile Care thank you.
3+
4+
Regards,
5+
Bungelina Bigglesnorf
6+
Chairwoman, Miuvenile Care
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Dear Billy Neighbor,
2+
Thank you for your generous gifts of $0.54, $0.01 and $0.25. Your donations, totalling $0.80, will go towards feeding homeless kittens in Seattle. From the bottom of our hearts, we at Miuvenile Care thank you.
3+
4+
Regards,
5+
Bungelina Bigglesnorf
6+
Chairwoman, Miuvenile Care
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Dear Dad,
2+
Thank you for your generous gifts of $20 and $5. Your donations, totalling $25, will go towards feeding homeless kittens in Seattle. From the bottom of our hearts, we at Miuvenile Care thank you.
3+
4+
Regards,
5+
Bungelina Bigglesnorf
6+
Chairwoman, Miuvenile Care
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Dear Donald Trump,
2+
Thank you for your generous gift of $2.81. Your donation will go towards feeding homeless kittens in Seattle. From the bottom of our hearts, we at Miuvenile Care thank you.
3+
4+
Regards,
5+
Bungelina Bigglesnorf
6+
Chairwoman, Miuvenile Care
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Dear Elon Musk,
2+
Thank you for your generous gifts of $10,000, $150,000 and $100,000. Your donations, totalling an incredible $260,000, will go towards feeding homeless kittens in Seattle. From the bottom of our hearts, we at Miuvenile Care thank you.
3+
4+
Regards,
5+
Bungelina Bigglesnorf
6+
Chairwoman, Miuvenile Care

0 commit comments

Comments
 (0)