Last active
July 26, 2016 17:02
-
-
Save zohaad/81268adeabc8c9c7a27adfe855034dcb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
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
Very nice solution! I might rename the parameters
a
andb
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!