listing2-3.py 550 B

12345678910111213141516
  1. # Prints a sentence in a centered "box" of correct width
  2. sentence = input("Sentence: ")
  3. screen_width = 80
  4. text_width = len(sentence)
  5. box_width = text_width + 6
  6. left_margin = (screen_width - box_width) // 2
  7. print()
  8. print(' ' * left_margin + '+' + '-' * (box_width-2) + '+')
  9. print(' ' * left_margin + '| ' + ' ' * text_width + ' |')
  10. print(' ' * left_margin + '| ' + sentence + ' |')
  11. print(' ' * left_margin + '| ' + ' ' * text_width + ' |')
  12. print(' ' * left_margin + '+' + '-' * (box_width-2) + '+')
  13. print()