Input Format
The first line contains a string, .
The second line contains the width, .
Constraints
Output Format
Print the text wrapped paragraph.
Hackerrank text wrap problem solution in python

Problem solution in python 2 programming language.

import textwrap
S = raw_input()
w = input()
print textwrap.fill(S,w)

Problem solution in python 3 programming language.

import textwrap
S = input()
w = input()
print textwrap.fill(S,w)

second solution

import textwrap
def wrap(string, max_width):
    wrapper = textwrap.TextWrapper(width=max_width) 
    dedented_text = textwrap.dedent(text=string) 
    result = wrapper.fill(text=dedented_text) 
    return result
if __name__ == '__main__':
    string, max_width = input(), int(input())
    result = wrap(string, max_width)
    print(result)