Skip to content

Instantly share code, notes, and snippets.

@drazenz
Last active August 19, 2021 15:18
Show Gist options
  • Select an option

  • Save drazenz/8af60869b909bd2f4e7d19de05b4adca to your computer and use it in GitHub Desktop.

Select an option

Save drazenz/8af60869b909bd2f4e7d19de05b4adca to your computer and use it in GitHub Desktop.
import string
def print_center(text:str) -> None:
term_len = 80
printable = ''.join([c for c in text if c in string.printable])
lines = printable.splitlines()
if len(lines) > 1:
for line in lines: print_center(line)
elif len(printable) > term_len:
print(printable[:term_len])
print_center(printable[term_len:])
else:
print(printable.center(term_len))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment