Newbie Question about sequence multiplication
attn.steven.kuo at gmail.com
attn.steven.kuo at gmail.com
Wed Apr 4 20:36:07 EDT 2007
On Apr 4, 3:19 pm, "Scott" <s_brosci... at comcast.net> wrote:
(snipped)
>
> print
> print ' ' * 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
>
> ****end code****
>
> Now that, even though copied straight from "Beginning Python: From Novice to
> Professional", returns :
> There's an error in your program: invalid syntax
>
(snipped)
Others have pointed out the mistake. I'll just add that in
this particular case, one might want to pad lines with some
whitespace and change the middle print statement to:
print
print ' ' * left_margin + '+' + '-' * box_width + '+'
print ' ' * left_margin + '|' + '-' * box_width + '|'
print ' ' * left_margin + '|' + sentence.center(box_width) + '|'
print ' ' * left_margin + '|' + '-' * box_width + '|'
print ' ' * left_margin + '+' + '-' * box_width + '+'
to improve legibility.
--
Hope this helps,
Steven
More information about the Python-list
mailing list