Text Wrap - HackerRank Python String Problem Solution

Author: Al-mamun Sarkar Date: 2020-03-23 20:38:45

Text Wrap - HackerRank Python String Problem Solution. The task is to wrap the string into a paragraph. Use the fill function of textwrap module. Click here to see the problem.

Code:

import textwrap

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


if __name__ == '__main__':
    string, max_width = input(), int(input())
    result = wrap(string, max_width)
    print(result)

 

Test Input:

ABCDEFGHIJKLIMNOQRSTUVWXYZ
4

Test Output:

ABCD
EFGH
IJKL
IMNO
QRST
UVWX
YZ