[Tutor] help: space formatting for multiplication table

Lee Harr missive at hotmail.com
Sun May 15 00:24:06 CEST 2005


>The idea is to print out a multiplication table on the command line
>with numbers lining up in the ones column. I want to eventually
>emulate programs like top with their spacing. But this code is mostly
>for my amusement. How would you make this work?
>


Try print string formatting using %

>>>print '%5d' % 12
   12
>>>print '--%5d--' % 12
--   12--
>>>print '--%5d--' % 112
--  112--
>>>print '--%5d--' % 1123
-- 1123--
>>>print '--%5d--' % 11235
--11235--
>>>print '--%5d--' % 112356
--112356--
>>>print '--%05d--' % 112
--00112--


http://docs.python.org/lib/typesseq-strings.html

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE! 
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/



More information about the Tutor mailing list