Newbie, homework help, please.

BartC bc at freeuk.com
Sat Apr 21 14:45:45 EDT 2012


"someone" <wesbroom at gmail.com> wrote in message 
news:32945367.2045.1335029313436.JavaMail.geo-discussion-forums at ynjn4...

> 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      *
> *                     *
> ***********************

I'm not a Python programmer, but I'll have a go at the text formatting bit:

text=["First Name and Last","ENGR 109-X","Fall 2999","Format Example"]

maxwidth=0
for s in text:
 if len(s)>maxwidth: maxwidth=len(s)

vertinchlines=6    # assume 6 lines/inch
hozinchchars=10    # assume 10 chars/inch

hozmargin=" "*hozinchchars

newtext=[]
for i in range(vertinchlines):
 newtext.append("")

newtext.append(hozmargin+"*"*(maxwidth+4)+hozmargin)
newtext.append(hozmargin+"* "+" "*maxwidth+" *"+hozmargin)

for s in text:
 newtext.append(hozmargin+"* "+s+" "*(maxwidth-len(s))+" *"+hozmargin)

newtext.append(hozmargin+"* "+" "*maxwidth+" *"+hozmargin)
newtext.append(hozmargin+"*"*(maxwidth+4)+hozmargin)

for i in range(vertinchlines):
 newtext.append("")

for s in newtext:
 print (s)

-- 
Bartc  



More information about the Python-list mailing list