02_4.py 673 B

12345678910111213141516171819202122232425
  1. #!/usr/bin/env python3
  2. # 序列相加
  3. print([1, 2, 3, 4]+[6, 7, 8, 9]) # [1,2,3,4,5,6,7,8,9]
  4. # 乘法
  5. print([42]*10) # [42, 42, 42, 42, 42, 42, 42, 42, 42, 42]
  6. # None、空列表和初始化
  7. sentence = input("Sentence: ")
  8. screen_width = 80
  9. text_width = len(sentence)
  10. box_width = text_width + 6
  11. left_margin = (screen_width - box_width) // 2
  12. print(left_margin)
  13. print()
  14. print(' ' * left_margin + '+' + '-' * (box_width-2) + '+')
  15. print(' ' * left_margin + '| ' + ' ' * text_width + ' |')
  16. print(' ' * left_margin + '| ' + sentence + ' |')
  17. print(' ' * left_margin + '| ' + ' ' * text_width + ' |')
  18. print(' ' * left_margin + '+' + '-' * (box_width-2) + '+')
  19. print()