listing2-3.py

来自「《Beginning Python--From Novice to Profes」· Python 代码 · 共 20 行

PY
20
字号
# Prints a sentence in a centered "box" of correct width# Note that the integer division operator (//) only works in Python# 2.2 and newer. In earlier versions, simply use plain division (/)sentence = raw_input("Sentence: ")screen_width = 80text_width   = len(sentence)box_width    = text_width + 6left_margin  = (screen_width - box_width) // 2printprint ' ' * left_margin + '+'   + '-' * (box_width-2)  +   '+'print ' ' * left_margin + '|  ' + ' ' * text_width     + '  |'print ' ' * left_margin + '|  ' +       sentence       + '  |'print ' ' * left_margin + '|  ' + ' ' * text_width     + '  |'print ' ' * left_margin + '+'   + '-' * (box_width-2)  +   '+'print

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?