For this program, the first line of input is an integer width. Then, there are some lines of text; the line "END" indicates the end of the text. For each line of text, you need to print out a centered version of it, by adding periods .. to the left and right, so that the total length of each line of text is width. (All input lines will have length at most width.) Centering means that the number of periods added to the left and added to the right should be equal if possible; if needed we allow one more period on the left than the right.
The code outputs desired results for the first two lines of input, but doesn't print the rest of input. I'm not sure what to do from here.
width=int(input())
line1=str(input())
line2=str(input())
line3=str(input())
line4=str(input())
line5=str(input())
for a in [line1,line2,line3, line4, line5]:
lenLin=len(a)
aopor=width-lenLin
aopor=aopor//2
aopor=aopor*"."
a=a+aopor
a=aopor+a
lenLin=len(a)
if lenLin<width:
a="."+a
print(a)

New Topic/Question
Reply



MultiQuote



|