Text Wrap || Hackerrank Solution

 Text Wrap:

You are given a string  and width .
Your task is to wrap the string into a paragraph of width .

Input Format

The first line contains a string, .
The second line contains the width, .

Constraints

Output Format

Print the text wrapped paragraph.

Sample Input 0

ABCDEFGHIJKLIMNOQRSTUVWXYZ
4

Sample Output 0

ABCD
EFGH
IJKL
IMNO
QRST
UVWX
YZ
  • Solution:
import textwrap

def wrap(string, max_width):
    return textwrap.fill(string, max_width)


🙏THANKS FOR VISIT🙏



Text Wrap || Hackerrank Solution Text Wrap || Hackerrank Solution Reviewed by CodexRitik on November 09, 2020 Rating: 5

No comments:

Powered by Blogger.