Tanmay :
Not able to place 'a' between the lines I was able to write the code for only the grid :
def draw_grid_art_four():
a = "+ - - - - + - - - - + - - - - +"
def do_twice(f):
f()
f()
def do_four(f):
do_twice(f)
do_twice(f)
def vertical():
b = "| | | |"
print(b)
print(a)
do_four(vertical)
print(a)
do_four(vertical)
print(a)
do_four(vertical)
print(a)
do_four(vertical)
print(a)
draw_grid_art_four()
Also it would be helpful if you can suggest me how to make this code shorter ( I am a beginner )
moxy :
Try to use recursive function as below, it is easier to code and also read. Are you looking for something like that?
def displayA(col, index):
if index == 0:
return
print(col * '| a a a a ' + '|')
return displayA(col, index-1)
def repeat(row, col):
if row == 0:
return
print(col * '+ - - - - ' + '+')
displayA(col, col+1)
return repeat(row-1, col)
def box(row, col):
repeat(row, col)
print(col * '+ - - - - ' + '+')
box(4,3)
Output:
+ - - - - + - - - - + - - - - +
| a a a a | a a a a | a a a a |
| a a a a | a a a a | a a a a |
| a a a a | a a a a | a a a a |
| a a a a | a a a a | a a a a |
+ - - - - + - - - - + - - - - +
| a a a a | a a a a | a a a a |
| a a a a | a a a a | a a a a |
| a a a a | a a a a | a a a a |
| a a a a | a a a a | a a a a |
+ - - - - + - - - - + - - - - +
| a a a a | a a a a | a a a a |
| a a a a | a a a a | a a a a |
| a a a a | a a a a | a a a a |
| a a a a | a a a a | a a a a |
+ - - - - + - - - - + - - - - +
| a a a a | a a a a | a a a a |
| a a a a | a a a a | a a a a |
| a a a a | a a a a | a a a a |
| a a a a | a a a a | a a a a |
+ - - - - + - - - - + - - - - +
Guess you like
Origin http://10.200.1.11:23101/article/api/json?id=390406&siteId=1