In: Computer Science
In Python, your program will read in a number (no need to prompt the user), and then reads in that number of lines from the terminal. Then the program should print an array of strings formatted in a nice regular box.
So if the user inputs this:
5 Grim visaged war has smooth’d his wrinkled front And now, instead of mounting barded steeds To fright the souls of fearful adversaries He capers nimbly in a lady’s chamber To the lascivious pleasing of a lute
The program should print:
++++++++++++++++++++++++++++++++++++++++++++++++++++ + Grim visaged war has smooth’d his wrinkled front + + And now, instead of mounting barded steeds + + To fright the souls of fearful adversaries + + He capers nimbly in a lady’s chamber + + To the lascivious pleasing of a lute + ++++++++++++++++++++++++++++++++++++++++++++++++++++
Hints
Please find below code and don't forget to give a Like.
Please refer below screenshot for indentation adn output. Explanation is given in comments of the code
Code:
def result(list1): length=0 for i in list1: #for getting the maximum line if(len(i)>length): length=len(i) print("+"*(length+10))#header for i in list1: space=length-len(i) #except the large line other require spaces print("+ ",i," "*space,"+")#giving spaces print("+" * (length+10))#footer n=int(input("Enter number of lines"))#taking input from user list_of_lines=[]#list of lines while(n!=0):#to read all lines string1=input() list_of_lines.append(string1)#appending n-=1 result(list_of_lines)#calling function to print result
Output: