Skip to content

Commit 003ca7f

Browse files
committed
For completeness, push up the homework assignment from the first session as well.
1 parent 6cf06d7 commit 003ca7f

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# a function which takes on a single argument defining the size
2+
# of a grid to draw
3+
4+
def print_grid(gridsize):
5+
# define the top and bottom portion of a single grid cell
6+
corner = "+"
7+
midtopbot = 4 * "-"
8+
9+
# define the center of a single grid cell
10+
gridcenter = "|" + 4 * " "
11+
12+
# define how to draw the complete top, bottom, and middle of the
13+
# full grid in a single direction
14+
topbot = gridsize * (corner + midtopbot) + corner
15+
center = gridsize * gridcenter + "|"
16+
17+
# build the grid in one direction
18+
onedirgrid = topbot + "\n"
19+
onedirgrid += 4 * (center + "\n")
20+
21+
#build the full grid
22+
grid = gridsize * onedirgrid + topbot
23+
24+
# now print the grid
25+
print grid
26+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# draws a grid using the buildgrid function after prompting the
2+
# user for the size of the grid
3+
4+
import buildgrid
5+
6+
try:
7+
size = int(raw_input("What size grid would you like to build? "))
8+
buildgrid.print_grid(size)
9+
except ValueError:
10+
print "Please enter an integer!"

0 commit comments

Comments
 (0)