How would you make this piece of code more simple/efficient? The problem should not be solved with one print statement, rather with functions
Could you also give me any advice how I can come to your simplified solution next time?
Code Used
def draw_pattern_1(p,m):
print(p, end=' ')
print(m, end=' ')
print(m, end=' ')
print(m, end=' ')
print(m, end=' ')
print(p, end=' ')
print(m, end=' ')
print(m, end=' ')
print(m, end=' ')
print(m, end=' ')
print(p)
def draw_pattern_2(l):
print(l, end=' ')
print(l, end=' ')
print(l)
def draw_grid(f_1,f_2,p,m,l):
draw_pattern_1(p,m)
draw_pattern_2(l)
draw_pattern_2(l)
draw_pattern_2(l)
draw_pattern_2(l)
draw_pattern_1(p,m)
draw_pattern_2(l)
draw_pattern_2(l)
draw_pattern_2(l)
draw_pattern_2(l)
draw_pattern_1(p,m)
p= "+"
m = "-"
l = "|"
draw_grid(draw_pattern_1,draw_pattern_2,p,m,l)
Output Generated
+ - - - - + - - - - +
| | |
| | |
| | |
| | |
+ - - - - + - - - - +
| | |
| | |
| | |
| | |
+ - - - - + - - - - +
draw_grid("unused", NotImplemented, p, m, l)
does the same thing asdraw_grid(draw_pattern_1, draw_pattern_2, p, m, l)
, which is probably not what you intended. \$\endgroup\$