Newbie, homework help, please.

S

someone

Ok, this is my dillema, not only am I new to this programming buisness, before the last few days, I did not even know what python was, and besides opening up the internet or word documents, that is most of what I know. Yet, Ihave a professor who should be on Psych medication for giving us 3 projects, 2 of which I have not listed here to do. I was able to do research over the last 3 days, and I have spent 3 days on this project, by borrowing others ideas on this project. Below, you will find my professors assignment (oh, and due in one week right before finals, so I am stressing out so much, cause I don't know why he is crazy enough to assign crap like this a week before finals when I have Calculus final,chem final, etc. I have figured out most of the assignment, and below, it will be posted after the teacher's post of the assignment. What I need help with, and I have tried relentlessly to find, is how to put freaking stars(asterisks) as border around a list without installing any other program to a portable python, of course, this iswhere my problem lies. Below, you will see what I have done, please, help!!!
You are required to complete and submit the following programming projects in Python by the indicated deadline:

Standard Header Information project (5 pts):
Write a program that will:
1) Ask the user for the following information:
- name of file to be created for storing SHI
- user’s name (as part of SHI)
- user’s course and section (as part of SHI)
- user’s semester and year (as part of SHI)
- user’s assignment title (as part of SHI)
2) Write the above SHI data to a text (.txt) file with the name chosen by the user (above)
3) Close the file that the SHI data was written to
4) Open the file with the SHI data (again)
5) Read the data into different (from part 1) variable names
6) Display the SHI data read from the file in the interpreter with a borderaround 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 *
* *
***********************


textfile=input('Hello, we are about to create a text file. An example would be: (sample.txt) without the parenthesis. What ever you do name it, it needs to end in (.txt). What would you like to name your textfile?')
userinput=[input('What is your name?'),input('What is your Course Sectionand Course number?'),input('What is the Semester and year?'),input('What is the title of this class assignment?')]
for item in userinput:
openfile=open(textfile,'w');openfile.writelines("%s\n" % item for item in userinput);openfile.close()
x=textfile;indat=open(x,'r');SHI=indat.read()
def border(Sullivan):
string=SHI
stringlength=len(string)
stringlength=stringlength("%s\n" % item for item in stringlength) + 2* (3 + 3)
hBorder=stringlength//2*"* "+"*"[:stringlength%2]
spacer="*"+" "*(stringlength - 2)+"*"
fancyText="* "+string+" *"
return(hBorder,spacer,fancyText,hBorder)

textTuple = border(SHI)
for lines in textTuple:
print (lines)
 
S

someone

Ok, this is my dillema, not only am I new to this programming buisness, before the last few days, I did not even know what python was, and besides opening up the internet or word documents, that is most of what I know. Yet,I have a professor who should be on Psych medication for giving us 3 projects, 2 of which I have not listed here to do. I was able to do research over the last 3 days, and I have spent 3 days on this project, by borrowing others ideas on this project. Below, you will find my professors assignment (oh, and due in one week right before finals, so I am stressing out so much,cause I don't know why he is crazy enough to assign crap like this a week before finals when I have Calculus final,chem final, etc. I have figured out most of the assignment, and below, it will be posted after the teacher's post of the assignment. What I need help with, and I have tried relentlessly to find, is how to put freaking stars(asterisks) as border around a list without installing any other program to a portable python, of course, this is where my problem lies. Below, you will see what I have done, please, help!!!
You are required to complete and submit the following programming projects in Python by the indicated deadline:

Standard Header Information project (5 pts):
Write a program that will:
1) Ask the user for the following information:
- name of file to be created for storing SHI
- user’s name (as part of SHI)
- user’s course and section (as part of SHI)
- user’s semester and year (as part of SHI)
- user’s assignment title (as part of SHI)
2) Write the above SHI data to a text (.txt) file with the name chosen bythe user (above)
3) Close the file that the SHI data was written to
4) Open the file with the SHI data (again)
5) Read the data into different (from part 1) variable names
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 borderand SHI data). An example might look like:

***********************
* *
* First Name and Last *
* ENGR 109-X *
* Fall 2999 *
* Format Example *
* *
***********************


textfile=input('Hello, we are about to create a text file. An example would be: (sample.txt) without the parenthesis. What ever you do name it, itneeds to end in (.txt). What would you like to name your textfile?')
userinput=[input('What is your name?'),input('What is your Course Section and Course number?'),input('What is the Semester and year?'),input('Whatis the title of this class assignment?')]
for item in userinput:
openfile=open(textfile,'w');openfile.writelines("%s\n" % item for item in userinput);openfile.close()
x=textfile;indat=open(x,'r');SHI=indat.read()
def border(Sullivan):
string=SHI
stringlength=len(string)
stringlength=stringlength("%s\n" % item for item in stringlength) +2 * (3 + 3)
hBorder=stringlength//2*"* "+"*"[:stringlength%2]
spacer="*"+" "*(stringlength - 2)+"*"
fancyText="* "+string+" *"
return(hBorder,spacer,fancyText,hBorder)

textTuple = border(SHI)
for lines in textTuple:
print (lines)

almost forgot, it has to have a 1 inch border around the top, bottom, left,and right, with it being aligned to the left. In the picture above, that is not how it actually looks, the stars to the right are aligned on the right, not right next to each other. Thanks.
 
J

Jon Clements

Ok, this is my dillema, not only am I new to this programming buisness,before the last few days, I did not even know what python was, and besidesopening up the internet or word documents, that is most of what I know. Yet, I have a professor who should be on Psych medication for giving us 3 projects, 2 of which I have not listed here to do. I was able to do research over the last 3 days, and I have spent 3 days on this project, by borrowing others ideas on this project. Below, you will find my professors assignment(oh, and due in one week right before finals, so I am stressing out so much, cause I don't know why he is crazy enough to assign crap like this a week before finals when I have Calculus final,chem final, etc. I have figured out most of the assignment, and below, it will be posted after the teacher's post of the assignment. What I need help with, and I have tried relentlessly to find, is how to put freaking stars(asterisks) as border around a list without installing any other program to a portable python, of course, this is where my problem lies. Below, you will see what I have done, please, help!!!
You are required to complete and submit the following programming projects in Python by the indicated deadline:

Standard Header Information project (5 pts):
Write a program that will:
1) Ask the user for the following information:
- name of file to be created for storing SHI
- user’s name (as part of SHI)
- user’s course and section (as part of SHI)
- user’s semester and year (as part of SHI)
- user’s assignment title (as part of SHI)
2) Write the above SHI data to a text (.txt) file with the name chosen by the user (above)
3) Close the file that the SHI data was written to
4) Open the file with the SHI data (again)
5) Read the data into different (from part 1) variable names
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 *
* *
***********************


textfile=input('Hello, we are about to create a text file. An examplewould be: (sample.txt) without the parenthesis. What ever you do name it, it needs to end in (.txt). What would you like to name your textfile?')
userinput=[input('What is your name?'),input('What is your Course Section and Course number?'),input('What is the Semester and year?'),input('What is the title of this class assignment?')]
for item in userinput:
openfile=open(textfile,'w');openfile.writelines("%s\n" % item foritem in userinput);openfile.close()
x=textfile;indat=open(x,'r');SHI=indat.read()
def border(Sullivan):
string=SHI
stringlength=len(string)
stringlength=stringlength("%s\n" % item for item in stringlength)+ 2 * (3 + 3)
hBorder=stringlength//2*"* "+"*"[:stringlength%2]
spacer="*"+" "*(stringlength - 2)+"*"
fancyText="* "+string+" *"
return(hBorder,spacer,fancyText,hBorder)

textTuple = border(SHI)
for lines in textTuple:
print (lines)

almost forgot, it has to have a 1 inch border around the top, bottom, left, and right, with it being aligned to the left. In the picture above, thatis not how it actually looks, the stars to the right are aligned on the right, not right next to each other. Thanks.

Honestly phrased question - well done.

Look at the textwrap module - I have no idea how you'll got an inch outputting in just text, as I might have a slightly different font setting and logical and physical inches are different.

Good luck, Jon.
 
B

BartC

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)
 
R

Roy Smith

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().
 
S

someone

Ok, this is my dillema, not only am I new to this programming buisness, before the last few days, I did not even know what python was, and besides opening up the internet or word documents, that is most of what I know. Yet,I have a professor who should be on Psych medication for giving us 3 projects, 2 of which I have not listed here to do. I was able to do research over the last 3 days, and I have spent 3 days on this project, by borrowing others ideas on this project. Below, you will find my professors assignment (oh, and due in one week right before finals, so I am stressing out so much,cause I don't know why he is crazy enough to assign crap like this a week before finals when I have Calculus final,chem final, etc. I have figured out most of the assignment, and below, it will be posted after the teacher's post of the assignment. What I need help with, and I have tried relentlessly to find, is how to put freaking stars(asterisks) as border around a list without installing any other program to a portable python, of course, this is where my problem lies. Below, you will see what I have done, please, help!!!
You are required to complete and submit the following programming projects in Python by the indicated deadline:

Standard Header Information project (5 pts):
Write a program that will:
1) Ask the user for the following information:
- name of file to be created for storing SHI
- user’s name (as part of SHI)
- user’s course and section (as part of SHI)
- user’s semester and year (as part of SHI)
- user’s assignment title (as part of SHI)
2) Write the above SHI data to a text (.txt) file with the name chosen bythe user (above)
3) Close the file that the SHI data was written to
4) Open the file with the SHI data (again)
5) Read the data into different (from part 1) variable names
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 borderand SHI data). An example might look like:

***********************
* *
* First Name and Last *
* ENGR 109-X *
* Fall 2999 *
* Format Example *
* *
***********************


textfile=input('Hello, we are about to create a text file. An example would be: (sample.txt) without the parenthesis. What ever you do name it, itneeds to end in (.txt). What would you like to name your textfile?')
userinput=[input('What is your name?'),input('What is your Course Section and Course number?'),input('What is the Semester and year?'),input('Whatis the title of this class assignment?')]
for item in userinput:
openfile=open(textfile,'w');openfile.writelines("%s\n" % item for item in userinput);openfile.close()
x=textfile;indat=open(x,'r');SHI=indat.read()
def border(Sullivan):
string=SHI
stringlength=len(string)
stringlength=stringlength("%s\n" % item for item in stringlength) +2 * (3 + 3)
hBorder=stringlength//2*"* "+"*"[:stringlength%2]
spacer="*"+" "*(stringlength - 2)+"*"
fancyText="* "+string+" *"
return(hBorder,spacer,fancyText,hBorder)

textTuple = border(SHI)
for lines in textTuple:
print (lines)

Thanks your Bart for trying, I don't understand how it works or if you tried to place my script in python to see if it would work, unfortunately, I tried 10 different ways plus yours, and I don't see the connection. Unless you were trying to help me see the way and I did not, sorry, but thanks for trying. The characters did show me a little more.
 
S

someone

Ok, this is my dillema, not only am I new to this programming buisness, before the last few days, I did not even know what python was, and besides opening up the internet or word documents, that is most of what I know. Yet,I have a professor who should be on Psych medication for giving us 3 projects, 2 of which I have not listed here to do. I was able to do research over the last 3 days, and I have spent 3 days on this project, by borrowing others ideas on this project. Below, you will find my professors assignment (oh, and due in one week right before finals, so I am stressing out so much,cause I don't know why he is crazy enough to assign crap like this a week before finals when I have Calculus final,chem final, etc. I have figured out most of the assignment, and below, it will be posted after the teacher's post of the assignment. What I need help with, and I have tried relentlessly to find, is how to put freaking stars(asterisks) as border around a list without installing any other program to a portable python, of course, this is where my problem lies. Below, you will see what I have done, please, help!!!
You are required to complete and submit the following programming projects in Python by the indicated deadline:

Standard Header Information project (5 pts):
Write a program that will:
1) Ask the user for the following information:
- name of file to be created for storing SHI
- user’s name (as part of SHI)
- user’s course and section (as part of SHI)
- user’s semester and year (as part of SHI)
- user’s assignment title (as part of SHI)
2) Write the above SHI data to a text (.txt) file with the name chosen bythe user (above)
3) Close the file that the SHI data was written to
4) Open the file with the SHI data (again)
5) Read the data into different (from part 1) variable names
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 borderand SHI data). An example might look like:

***********************
* *
* First Name and Last *
* ENGR 109-X *
* Fall 2999 *
* Format Example *
* *
***********************


textfile=input('Hello, we are about to create a text file. An example would be: (sample.txt) without the parenthesis. What ever you do name it, itneeds to end in (.txt). What would you like to name your textfile?')
userinput=[input('What is your name?'),input('What is your Course Section and Course number?'),input('What is the Semester and year?'),input('Whatis the title of this class assignment?')]
for item in userinput:
openfile=open(textfile,'w');openfile.writelines("%s\n" % item for item in userinput);openfile.close()
x=textfile;indat=open(x,'r');SHI=indat.read()
def border(Sullivan):
string=SHI
stringlength=len(string)
stringlength=stringlength("%s\n" % item for item in stringlength) +2 * (3 + 3)
hBorder=stringlength//2*"* "+"*"[:stringlength%2]
spacer="*"+" "*(stringlength - 2)+"*"
fancyText="* "+string+" *"
return(hBorder,spacer,fancyText,hBorder)

textTuple = border(SHI)
for lines in textTuple:
print (lines)

Thanks for your reply Mr. Roy Smith. Also, thanks for the tip. Maybe I did not make myself as clear or maybe you did not understand my post. It stateshomework help, and I am doing this post to get help before I pay somebody to show me how to do it, because, obviously our professor is not kind enough to show us how to do this less than two weeks before the due date with 3 projects (and now I have basically less than a week before it is due- and Iam not waiting till the last minute), and this just so happens to be the easier one. I understand the concept of him trying to give us deadlines and making us learn, but I don't appreciate paying for a class where I am not taught anything or told the right direction due to his belief that he is helping me to get a stronger work ethic, I have 5 classes this semester, and stupid me, I had to take the hardest ones I could not realizing the depth ofthe struggles I would face. Again, thanks for the tip, but I never asked you to do my homework, it clearly states that I did research over the last few days, over the internet, because our brilliant professor is giving us just the slim end of what he believes is enough to get us through. I took posted script and made it work by figuring it out to fit the assignment. At least, I am trying, want to guess at how many people have buddies in this class and they will copy this off of them before due date? Please, don't judgepeople because you think you are doing me a favor by saying you will not do my homework for me, I never asked, I said help.
 
G

GrayShark

A lot of to do about this.




-----------------------
#!/usr/bin/python


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

xl_max = 0
for x in xl:
xl_max = max ( len( x ), xl_max )

topBorder = '^'*( xl_max + 4 )

print topBorder
for x in xl:
print "* %s%s *" % ( x, ' '*(xl_max - len( x )) )
print topBorder
-----------------------


Ok, this is my dillema, not only am I new to this programming buisness, before the last few days, I did not even know what python was, and besides opening up the internet or word documents, that is most of what I know. Yet,I have a professor who should be on Psych medication for giving us 3 projects, 2 of which I have not listed here to do. I was able to do research over the last 3 days, and I have spent 3 days on this project, by borrowing others ideas on this project. Below, you will find my professors assignment (oh, and due in one week right before finals, so I am stressing out so much,cause I don't know why he is crazy enough to assign crap like this a week before finals when I have Calculus final,chem final, etc. I have figured out most of the assignment, and below, it will be posted after the teacher's post of the assignment. What I need help with, and I have tried relentlessly to find, is how to put freaking stars(asterisks) as border around a list without installing any other program to a portable python, of course, this is where my problem lies. Below, you will see what I have done, please, help!!!
You are required to complete and submit the following programming projects in Python by the indicated deadline:

Standard Header Information project (5 pts):
Write a program that will:
1) Ask the user for the following information:
- name of file to be created for storing SHI
- user’s name (as part of SHI)
- user’s course and section (as part of SHI)
- user’s semester and year (as part of SHI)
- user’s assignment title (as part of SHI)
2) Write the above SHI data to a text (.txt) file with the name chosen bythe user (above)
3) Close the file that the SHI data was written to
4) Open the file with the SHI data (again)
5) Read the data into different (from part 1) variable names
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 borderand SHI data). An example might look like:

***********************
* *
* First Name and Last *
* ENGR 109-X *
* Fall 2999 *
* Format Example *
* *
***********************


textfile=input('Hello, we are about to create a text file. An example would be: (sample.txt) without the parenthesis. What ever you do name it, itneeds to end in (.txt). What would you like to name your textfile?')
userinput=[input('What is your name?'),input('What is your Course Section and Course number?'),input('What is the Semester and year?'),input('Whatis the title of this class assignment?')]
for item in userinput:
openfile=open(textfile,'w');openfile.writelines("%s\n" % item for item in userinput);openfile.close()
x=textfile;indat=open(x,'r');SHI=indat.read()
def border(Sullivan):
string=SHI
stringlength=len(string)
stringlength=stringlength("%s\n" % item for item in stringlength) +2 * (3 + 3)
hBorder=stringlength//2*"* "+"*"[:stringlength%2]
spacer="*"+" "*(stringlength - 2)+"*"
fancyText="* "+string+" *"
return(hBorder,spacer,fancyText,hBorder)

textTuple = border(SHI)
for lines in textTuple:
print (lines)
 
S

someone

Ok, this is my dillema, not only am I new to this programming buisness, before the last few days, I did not even know what python was, and besides opening up the internet or word documents, that is most of what I know. Yet,I have a professor who should be on Psych medication for giving us 3 projects, 2 of which I have not listed here to do. I was able to do research over the last 3 days, and I have spent 3 days on this project, by borrowing others ideas on this project. Below, you will find my professors assignment (oh, and due in one week right before finals, so I am stressing out so much,cause I don't know why he is crazy enough to assign crap like this a week before finals when I have Calculus final,chem final, etc. I have figured out most of the assignment, and below, it will be posted after the teacher's post of the assignment. What I need help with, and I have tried relentlessly to find, is how to put freaking stars(asterisks) as border around a list without installing any other program to a portable python, of course, this is where my problem lies. Below, you will see what I have done, please, help!!!
You are required to complete and submit the following programming projects in Python by the indicated deadline:

Standard Header Information project (5 pts):
Write a program that will:
1) Ask the user for the following information:
- name of file to be created for storing SHI
- user’s name (as part of SHI)
- user’s course and section (as part of SHI)
- user’s semester and year (as part of SHI)
- user’s assignment title (as part of SHI)
2) Write the above SHI data to a text (.txt) file with the name chosen bythe user (above)
3) Close the file that the SHI data was written to
4) Open the file with the SHI data (again)
5) Read the data into different (from part 1) variable names
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 borderand SHI data). An example might look like:

***********************
* *
* First Name and Last *
* ENGR 109-X *
* Fall 2999 *
* Format Example *
* *
***********************


textfile=input('Hello, we are about to create a text file. An example would be: (sample.txt) without the parenthesis. What ever you do name it, itneeds to end in (.txt). What would you like to name your textfile?')
userinput=[input('What is your name?'),input('What is your Course Section and Course number?'),input('What is the Semester and year?'),input('Whatis the title of this class assignment?')]
for item in userinput:
openfile=open(textfile,'w');openfile.writelines("%s\n" % item for item in userinput);openfile.close()
x=textfile;indat=open(x,'r');SHI=indat.read()
def border(Sullivan):
string=SHI
stringlength=len(string)
stringlength=stringlength("%s\n" % item for item in stringlength) +2 * (3 + 3)
hBorder=stringlength//2*"* "+"*"[:stringlength%2]
spacer="*"+" "*(stringlength - 2)+"*"
fancyText="* "+string+" *"
return(hBorder,spacer,fancyText,hBorder)

textTuple = border(SHI)
for lines in textTuple:
print (lines)

Thanks Bart for trying, it helped me out a little more by showing me a little more than I knew, but I tried and I am not sure if it does fit my example due to it was too many stars in between the lines, and not match up, but if you see any more help, that would be great, or see something I am doing wrong, or figure something out, let me know, have a great day, again, thanks
 
B

BartC

Thanks your Bart for trying, I don't understand how it works or if you
tried to place my script in python to see if it would work, unfortunately,
I tried 10 different ways plus yours, and I don't see the connection.
Unless you were trying to help me see the way and I did not, sorry, but
thanks for trying. The characters did show me a little more.

Did you run my code fragment on it's own to see if it did the job?

The code can be packaged into a function border() just like you already
have:

def border(text):
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("")

return newtext

And can be tested like this (obviously you will need to obtain SHI from the
input file):

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

textTuple = border(SHI)

for lines in textTuple:
print (lines)

The text handling is clunky (I had to learn the Python as I went along), but
with these things you just want to get something working first, then you can
tweak.
 
B

BartC

Thanks Bart for trying, it helped me out a little more by showing me a
little more than I knew, but I tried and I am not sure if it does fit my
example due to it was too many stars in between the lines, and not match
up, but if you see any more help, that would be great, or see something I
am doing wrong, or figure something out, let me know, have a great day,
again, thanks

Here's the example you posted:

***********************
* *
* First Name and Last *
* ENGR 109-X *
* Fall 2999 *
* Format Example *
* *
***********************

And here's the output from both bits of code I posted, which has 'one inch'
of white space all around; both examples must be viewed with a fixed-pitch
font (or in 'code' mode):






***********************
* *
* First Name and Last *
* ENGR 109-X *
* Fall 2999 *
* Format Example *
* *
***********************





Please post the output you're getting that has too many asterisks.
 
S

someone

Here's the example you posted:

***********************
* *
* First Name and Last *
* ENGR 109-X *
* Fall 2999 *
* Format Example *
* *
***********************

And here's the output from both bits of code I posted, which has 'one inch'
of white space all around; both examples must be viewed with a fixed-pitch
font (or in 'code' mode):






***********************
* *
* First Name and Last *
* ENGR 109-X *
* Fall 2999 *
* Format Example *
* *
***********************





Please post the output you're getting that has too many asterisks.

Hi, Bart: Thank you, your post is working now, maybe, I did something wrong, unfortunately, you are right, my setup for getting the file to pull up correctly now is an issue, At first, I got a Vertical line with it working, then I tried to tinker with it, and it fratched, lol
def border(text):
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("")
return newtext
x=textfile;indat=open(x,'r');SHI=indat.read()
textTuple = border(SHI)
for lines in textTuple:
print ("%s\n" %textTuple)


The issue is trying to get the SHI to work right, but omg, this is the closes I have gotten, you are awsome, thank you very much, i guess i will just keep messing with it till i get it
 
B

BartC

Hi, Bart: Thank you, your post is working now, maybe, I did something
wrong, unfortunately, you are right, my setup for getting the file to pull
up correctly now is an issue, At first, I got a Vertical line with it
working, then I tried to tinker with it, and it fratched, lol
def border(text):
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("")
return newtext
x=textfile;indat=open(x,'r');SHI=indat.read()
textTuple = border(SHI)
for lines in textTuple:
print ("%s\n" %textTuple)


The issue is trying to get the SHI to work right, but omg, this is the
closes I have gotten, you are awsome, thank you very much, i guess i will
just keep messing with it till i get it

I had to use this code to make this work right from a file (in additon to
the border() function):

textfile="kkk4" # (don't use this; this was my test input)

x=textfile;indat=open(x,'r');

SHI=indat.readlines()
indat.close()

for i in range(len(SHI)): # remove trailing '\n' from each line
s=SHI
SHI=(s[0:len(s)-1])

textTuple = border(SHI)

for lines in textTuple:
print (lines)

Your indat.read() seemed to read all the lines as one long string. I used
indat.readlines() instead. However each line has a newline char '\n' at the
end. I put in a loop to get rid of that (I'm sure there's a one-line fix to
do that, but as I said don't know Python).

The input file I used had to have this format:

First Name and Last
ENGR 109-X
Fall 2999
Format Example
 
S

someone

Thanks, Bart, it worked perfectly: I was the one doing wrong due to I was doing the indentation incorrectly, I messed it up and thought it was the code when it was me. Thank you so much, and have a blessed day.
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("")
return newtext
x=textfile;indat=open(x,'r');SHI=indat.read()
textTuple = border(SHI)
for lines in textTuple:
print ("%s\n" %textTuple)


The issue is trying to get the SHI to work right, but omg, this is the
closes I have gotten, you are awsome, thank you very much, i guess i will
just keep messing with it till i get it

I had to use this code to make this work right from a file (in additon to
the border() function):

textfile="kkk4" # (don't use this; this was my test input)

x=textfile;indat=open(x,'r');

SHI=indat.readlines()
indat.close()

for i in range(len(SHI)): # remove trailing '\n' from each line
s=SHI
SHI=(s[0:len(s)-1])

textTuple = border(SHI)

for lines in textTuple:
print (lines)

Your indat.read() seemed to read all the lines as one long string. I used
indat.readlines() instead. However each line has a newline char '\n' at the
end. I put in a loop to get rid of that (I'm sure there's a one-line fix to
do that, but as I said don't know Python).

The input file I used had to have this format:

First Name and Last
ENGR 109-X
Fall 2999
Format Example
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Help please 8
Please, help me. 1
Please help 2
Total Purchase. Please Help 1
I dont get this. Please help me!! 2
Need help,homework 6
Code help please 4
Homework help 9

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top