problem The objective is to build a program that receives a text and formats it in such a way that the text is divided into lines that do not exceed a given size n. In other words, each output line must have a length less than or equal to n, must respect the original order of the words, must include the maximum number of words possible per line, and must include only complete words separated by a space. Entry A line that contains the text to be divided and an integer n that corresponds to the maximum size of characters per line. n will always be greater than or equal to the size of the longest word in the text plus one. Words in the input text will be separated by one or more blank spaces. Departure
Python problem
The objective is to build a
Entry
A line that contains the text to be divided and an integer n that corresponds to the maximum size of characters per line. n will always be greater than or equal to the size of the longest word in the text plus one. Words in the input text will be separated by one or more blank spaces.
Departure
The first and last lines must contain a space, n characters "*" and another space at the end. Lines in the requested format must begin and end with the "|" character. The line must be completed before the "|" with spaces
Examples
Input Example 1
In Sumatra, someone wants to get a doctorate as a fortune teller. The examining witch asks him if he will be failed or if he will pass. The candidate responds that he will be failed.
twenty
Output Example 1
********************
| In Sumatra, someone |
| wants to get a doctorate from |
| I guess. The witcher |
| examiner him |
| ask if he will be |
| failed or if |
| will pass. The candidate |
| answer that it will be |
| failed. |
********************
Input Example 2
In Sumatra, someone wants to get a doctorate as a fortune teller. The examining sorcerer asks him if he will be failed or if he will pass. The candidate responds that he will be failed.
eleven
Output Example 2
***********
| In Sumatra, |
| someone |
| wants |
| get a doctorate |
| as a fortune teller. |
| The witcher |
| examiner |
| asks him |
| if it will be |
| failed or |
| if it will happen. |
| The |
| candidate |
| answer |
| what will be |
| failed. |
***********
Notes
The output must have a new line character at the end otherwise you may receive the wrong answer verdict.
Step by step
Solved in 2 steps