Text Wrap - HackerRank Python String Problem Solution

Text Wrap - HackerRank Python String Problem Solution

Instructor-svgAl-Mamun Sarkar
Mar 23 , 2020

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
  • Share On:
  • fb
  • twitter
  • pinterest
  • instagram