shape=' _____\n | |\n | |\n |_____|'
x=''
for i in range(2):
x=x shape_1
print(x)
I know this question has been asked a lot,but i can't find an answer for strings with shapes like this.I can't put the output because it looks weird,but it's 2 vertical rectangles.
Basically i want every time that i moves to start printing at the end of the first rectangle,so it would be 2 horizontal rectangles.
I have tried using the end function but to no avail.Is what i am trying to do possible or will the shape always get messed up.
CodePudding user response:
You have to draw the left edge and the body separately.
left=(
' ',
' |',
' |'
)
rest=(
'_____ ',
' |',
'_____|',
)
def drawboxes( width, height, rows ):
print(left[0] rest[0] * width )
for _ in range(height):
for y in range(rows):
print(left[1] rest[1] * width )
print(left[2] rest[2] * width )
drawboxes(4,3,2)
Output:
_____ _____ _____ _____
| | | | |
| | | | |
|_____|_____|_____|_____|
| | | | |
| | | | |
|_____|_____|_____|_____|
| | | | |
| | | | |
|_____|_____|_____|_____|
CodePudding user response:
Try this:
shape=' _____ \n | |\n | |\n |_____|'
shape_arr = shape.split('\n')
x = [i for j in zip(*[shape_arr] * 2) for i in j ('\n',)]
x = ''.join(x)
print(x)
The idea is to add a line after line without having '\n':
shape=' _____ _____ \n | | | |\n | | | |\n |_____| |_____|\n
Output
_____ _____
| | | |
| | | |
|_____| |_____|