In this HackerRank Text Wrap problem you are given a string s and width w. you need to wrap the string into a paragraph of width w.

HackerRank Text Wrap in python problem solution

HackerRank Text Wrap in python problem solution

# Enter your code here. Read input from STDIN. Print output to STDOUT
import textwrap
str = raw_input()
n = int(raw_input())
print textwrap.fill(str, n)

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)