The original code of the book:
=====================================================================================
#!/usr/bin/evn python
#encoding: Utf-8
Print a sentence #以正确的宽度在居中得 "box"
#注意, Integer division Operations (//) can only be used with Python 2.2 and later versions, only normal division (/) in previous versions
Sentence = Raw_input ("sentence:")
Screen_width = 80
Text_width = Len (sentence)
Box_width = text_width + 6
Left_margin = (screen_width-text_width)//2
Print
print ' * left_margin + ' + ' + '-' * (box_width) + ' + '
print ' * left_margin + ' | ' + ' * text_width + ' | '
print ' * left_margin + ' | ' + sentence + ' | '
print ' * left_margin + ' | ' + ' * text_width + ' | '
print ' * left_margin + ' + ' + '-' * (box_width) + ' + '
Print
=====================================================================================
Execution Result:
650) this.width=650; "title=" clipboard "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; border-left:0px; padding-right:0px "border=" 0 "alt=" clipboard "src=" http://s3.51cto.com/wyfs02/M02/79/2D/ Wkiom1akjajznymtaabemw5hgbe819.png "" 1105 "height=" 238 "/>
I modified the post code:
=====================================================================================
#!/usr/bin/evn python
#encoding: Utf-8
Print a sentence #以正确的宽度在居中得 "box"
#注意, Integer division Operations (//) can only be used with Python 2.2 and later versions, only normal division (/) in previous versions
Sentence = Raw_input ("sentence:")
Screen_width = 80
Text_width = Len (sentence)
Box_width = text_width + 6
Left_margin = Box_width + ((box_width-text_width)//2)
Print
print ' * box_width + ' + ' + '-' * (box_width) + ' + '
print ' * left_margin + ' | ' + ' * text_width + ' | '
print ' * left_margin + ' | ' + sentence + ' | '
print ' * left_margin + ' | ' + ' * text_width + ' | '
print ' * box_width + ' + ' + '-' * (box_width) + ' + '
Print
=====================================================================================
Execution Result:
650) this.width=650; "title=" clipboard[1] "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; border-left:0px; padding-right:0px "border=" 0 "alt=" clipboard[1] "src=" http://s3.51cto.com/wyfs02/M00/79/2D/ Wkiom1akjanayoq-aabdmia8tao130.png "" 1114 "height="/>
Reading conclusion:
Reading can choose to browse or can choose to personally put into practice, I read a book to choose any content will go through the practice, even if it is very simple print a line of content or 2 + 2 to do a calculation, I will go to do it manually, you do not perform the feeling is rightfully the result, you executed Oh, That's the result. There is no problem, but for me I always position myself very low, in fact, I have no reason not to do it, even if it is very simple. What you have to write in the book you can not guarantee that the author is not a bit wrong, you can find the wrong and to think exactly where the error, here is your own growth, you have to improve, the book can not give you.
This article from "A Dream" blog, reproduced please contact the author!
Turing "Basic Python Tutorial" version 2nd, code 2-3 questions