Skip to content

Instantly share code, notes, and snippets.

@larsaars
Created April 19, 2021 13:28
Show Gist options
  • Save larsaars/55eff24141da9a082c11c90f72ec8512 to your computer and use it in GitHub Desktop.
Save larsaars/55eff24141da9a082c11c90f72ec8512 to your computer and use it in GitHub Desktop.
print a text box with python
def text_box(width: int, height: int) -> str:
lx, ly = width - 1, height - 1
out = ''
for y in range(height):
for x in range(width):
if x == 0 or x == lx:
out += '+' if y == 0 or y == ly else '|'
elif y == 0 or y == ly:
out += '-'
else:
out += ' '
if x == lx and y != ly:
out += '\n'
return out
print(text_box(100, 15))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment