Newbie, homework help, please.

Roy Smith roy at panix.com
Sat Apr 21 15:44:02 EDT 2012


In article 
<32945367.2045.1335029313436.JavaMail.geo-discussion-forums at ynjn4>,
 someone <wesbroom at gmail.com> wrote:

I'm not going to do your homework for you (nor do I expect anybody else 
will), but I'll give you a hint about one sticky part.

> 6) Display the SHI data read from the file in the interpreter with a border 
> around the SHI data (include a buffer of 1 line/space between the border and 
> SHI data). An example might look like:
> 
> 	***********************
> 	*                     *
> 	* First Name and Last *
> 	* ENGR 109-X          *
> 	* Fall 2999           *
> 	* Format Example      *
> 	*                     *
> 	***********************

You can take advantage of python's string formatting capabilities (which 
are pretty much the same as C's printf() formatting), and do something 
like:

print  "* %-*s *" % (max_length, data)

That will at least get you the data left-justified with the correct 
number of spaces for padding.  See 
http://docs.python.org/library/stdtypes.html#string-formatting for 
details.  You'll need to compute max_length by applying len() to each of 
the individual strings in turn, and picking the largest of them with 
max().



More information about the Python-list mailing list