File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed
Students/imdavis/session01 Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change 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+
Original file line number Diff line number Diff line change 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!"
You can’t perform that action at this time.
0 commit comments