Created
April 19, 2021 13:28
-
-
Save larsaars/55eff24141da9a082c11c90f72ec8512 to your computer and use it in GitHub Desktop.
print a text box with python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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