Text Wrap in Python - HackerRank Solution
Problem Statement :
You are given a string S and width w.
Your task is to wrap the string into a paragraph of width w.
Input Format:
The first line contains a string, S.
The second line contains the width, w.
Constraints:
0<len(S)<1000
0<w<len(S)
Output Format:
Print the text wrapped paragraph.
Solution:
#The complete solution as needed for hackerrank challenge.
import textwrap
def wrap(string, max_width):
return textwrap.TextWrapper(width=max_width).fill(text=string)
if __name__ == '__main__':
string, max_width = input(), int(input())
result = wrap(string, max_width)
print(result)
Disclaimer:-
The above hole problem statement is given by hackerrank.com but the solution is generated by the Hackerranksolution.site authority if any of the queries regarding this post or website fill the following contact form thank you.