The following code function is: No matter how long you enter a sentence, you can build the corresponding size box and the statement is centered in the box ...
#!/usr/bin/env python# definition sentence = raw_input ("sentence: ") screen_with = 80text_ Width = len (sentence) box_width = text_width + 6left_margin = (screen_ with - text_width) // 2# picture box printprint ' ' * left_margin + ' + ' + '-' * box_width + ' + ' print ' ' * left_margin + ' | ' + ' ' * box_width + ' | ' print ' ' * left_margin + ' | ' + ' ' * ((box_width - text_width) // 2) + sentence + ' ' * ((box_width - text_width) // 2) + ' | ' print ' ' * left_margin + ' | ' + ' ' * box_width + ' | ' print ' ' * left_margin + ' + ' + '-' * box_width + ' + ' Print
This article is from the "Kysida" blog, make sure to keep this source http://hongtengfei.blog.51cto.com/9881650/1706064
Small box algorithm----statement written in the box centered