From daad9e085a2db01e864e2a8baa4c9f12d7f0de35 Mon Sep 17 00:00:00 2001 From: jerry yu Date: Sat, 5 Jun 2021 19:26:32 -0400 Subject: [PATCH] update grid.py to add the 3rd iteration by generalizing rows --- code/grid.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/code/grid.py b/code/grid.py index d716575..8d28ff3 100644 --- a/code/grid.py +++ b/code/grid.py @@ -93,6 +93,25 @@ def print_grid(): print_grid() +# here is even less-straightforward solution that can print grids of any size +def draw_row(repeat, cols, marker, filler): + for i in range(cols): + print(marker, filler * repeat, ' ', sep='', end='') + print(marker) + +def draw_grid(rows, cols, repeat=4): + draw_row(repeat, cols, '+', ' -') + for i in range(rows): + for i in range(repeat): + draw_row(repeat, cols, '|', ' ') + draw_row(repeat, cols, '+', ' -') + +def main(): + draw_grid(3, 3) + +if '__main__' == __name__: + main() + comment = """ After writing a draft of the 4x4 grid, I noticed that many of the functions had the same structure: they would do something, do