Skip to content

Instantly share code, notes, and snippets.

@zohaad
Last active July 26, 2016 17:02
Show Gist options
  • Save zohaad/81268adeabc8c9c7a27adfe855034dcb to your computer and use it in GitHub Desktop.
Save zohaad/81268adeabc8c9c7a27adfe855034dcb to your computer and use it in GitHub Desktop.
def verticals(arg): # making the verticals
print('| ' * arg, '|')
def do_four_times(f, arg): # 4 times repeater
f(arg)
f(arg)
f(arg)
f(arg)
def onestroke(dim, vert_func): # make one row
print('+ - - - - ' * dim, '+') # first, the line with the +'s
do_four_times(vert_func, dim) # then the 4 verticals
def dimstrokes(f, dim, one_func): # make "dim" rows
x = 1
while x <= dim:
f(dim, one_func)
x += 1
def draw_square(dim):
dimstrokes(onestroke, dim, verticals) # calling it
print('+ - - - - ' * dim, '+') # closing it off
draw_square(6)
@AllenDowney
Copy link

Very nice solution! I might rename the parameters a and b to clarify their roles.

(And I think the while loop is a bit of a cheat, since it doesn't appear in the book until after this exercise. )

Still, good stuff -- thanks!

@zohaad
Copy link
Author

zohaad commented Jul 26, 2016

Thanks for the input!

I changed the a to dim and the b to either vert_func or one_func to avoid confusion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment