Question

In: Computer Science

In Python, your program will read in a number (no need to prompt the user), and...

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

  • 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" * 4 returns "xxxx".
  • Then print the footer row. The length of the footer row depends on the length of the longest line.

Solutions

Expert Solution

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:


Related Solutions

I need a java code Write a simple program to prompt the user for a number...
I need a java code Write a simple program to prompt the user for a number between 1 and 12 (inclusive) and print out the corresponding month. For example:   The 12th month is December. Use a java "switch" statement to convert from the number (1-12) to the month. Also use a "do while" loop and conditional checking to validate that the number entered is between 1 and 12 inclusive and if not, prompt the user again until getting the correct...
Step by step in python please Write a program this will read a file (prompt for...
Step by step in python please Write a program this will read a file (prompt for name) containing a series of numbers (one number per line), where each number represents the radii of different circles. Have your program output a file (prompt for name) containing a table listing: the number of the circle (the order in the file) the radius of the circle the circumference the area of the circle the diameter of the circle Use different functions to calculate...
Create a python program that will: prompt a user for a command Command get_data Level 1:...
Create a python program that will: prompt a user for a command Command get_data Level 1: Take one of the commands my_max my_min my_range my_sum mean median mode fib factorize prime Requirements: Your commands should be case-insensitive You should use python lists to store data You should NOT use built-in python math functions, or math libraries to compute these values Tips: Write one function that will convert a string with comma-separated numbers into a python list with the numbers. You...
Design a Python program to prompt the user for temperatures for ten consecutive days in Celsius...
Design a Python program to prompt the user for temperatures for ten consecutive days in Celsius and store them into an array. The entire array should then be displayed. Next each temperature in the array should be converted to Fahrenheit and stored into a 2nd array. This entire array should then be displayed. The formula for converting Celsius to Fahrenheit is °F = (°C × 1.8) + 32. Finally, the number of cool, warm and hot days should be counted...
Write a C program Your program will prompt the user to enter a value for the...
Write a C program Your program will prompt the user to enter a value for the amount of expenses on the credit card. Retrieve the user input using fgets()/sscanf() and save the input value in a variable. The value should be read as type double. The user may or may not enter cents as part of the input. In other words, expect the user to enter values such as 500, 500.00 and 500.10. The program will then prompt the user...
A. Write a program 1. Prompt the user to enter a positive integer n and read...
A. Write a program 1. Prompt the user to enter a positive integer n and read in the input. 2. Print out n of Z shape of size n X n side by side which made up of *. B. Write a C++ program that 1. Prompt user to enter an odd integer and read in the value to n. 2. Terminate the program if n is not odd. 3. Print out a cross shape of size n X n...
Create a C++ program that will prompt the user to input an integer number and output...
Create a C++ program that will prompt the user to input an integer number and output the corresponding number to its numerical words. (From 0-1000000 only) **Please only use #include <iostream>, switch and if-else statements only and do not use string storing for the conversion in words. Thank you.** **Our class is still discussing on the basics of programming. Please focus only on the basics. Thank you.** Example outputs: Enter a number: 68954 Sixty Eight Thousand Nine Hundred Fifty Four...
Create a C++ program that will prompt the user to input an positive integer number and...
Create a C++ program that will prompt the user to input an positive integer number and output the corresponding number to words. Check all possible invalid input data. (Please use only switch or if-else statements. Thank you.)
Create a C++ program that will prompt the user to input an integer number and output...
Create a C++ program that will prompt the user to input an integer number and output the corresponding number to its numerical words. (From 0-1000000 only) **Please only use #include <iostream> and switch and if-else statements only. Thank you. Ex. Enter a number: 68954 Sixty Eight Thousand Nine Hundred Fifty Four Enter a number: 100000 One Hundred Thousand Enter a number: -2 Number should be from 0-1000000 only
1. Write a program in C++ to find the factorial of a number. Prompt the user...
1. Write a program in C++ to find the factorial of a number. Prompt the user for a number and compute the factorial by using the following expression. Use for loops to write your solution code. Factorial of n = n! = 1×2×3×...×n; where n is the user input. Sample Output: Find the factorial of a number: ------------------------------------ Input a number to find the factorial: 5 The factorial of the given number is: 120 2. Code problem 1 using While...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT