Question: Write a program niceregularbox.py . do this by using while and for loops Your program will read in a number, and then reads in that
Write a program niceregularbox.py do this by using "while" and "for" loops
Your program will read in a number, 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.
Example
If the user inputs this:
Grim visaged war has smoothd his wrinkled front
And now, instead of mounting barded steeds
To fright the souls of fearful adversaries
He capers nimbly in a ladys chamber
To the lascivious pleasing of a lute
The program should print:
Grim visaged war has smoothd his wrinkled front
And now, instead of mounting barded steeds
To fright the souls of fearful adversaries
He capers nimbly in a ladys chamber
To the lascivious pleasing of a lute
Example
If the user inputs:
Avengers, assemble!
Note the empty line between and Avengers, assemble. The program should print:
Avengers, assemble!
Example
If the user inputs:
The program should print:
Hints
Read in the number from the user with input then read that number of lines. Append each line that you read into a list of lines. If you don't remember how, Google "Python list append".
Find the length of the longest line. That determines the width of the box.
Then print the header row. The length of the header row depends on the length of the longest line.
Print each line.
For each line, you have to print some number of spaces at the end, depending on the difference between the length of the longest line and the length of the current line.
You have to print some repeated characters.
x n returns x repeated n times.
For instance, x returns xxxx
Then print the footer row. The length of the footer row depends on the length of the longest line.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
