-->

Text Wrap Hackerrank Solution In Python 3

Text Wrap Hackerrank Solution In Python 3


Hello Friends 

рдЖрдЬ рд╣рдо рдЖрдкрдХреЛ Hacker Rank рдкрд░ Text Wrap рдХрд╛ рдХрдВрдкреНрд▓реАрдЯ рд╕реЙрд▓реНрдпреВрд╢рди рдмрддрд╛рдПрдВрдЧреЗ рд╡рд╣ рднреА рдЖрд╕рд╛рди рднрд╛рд╖рд╛ рдореЗрдВред рддреЛ рджреЛрд╕реНрддреЛрдВ рдЪрд▓рд┐рдП рдЬрд╛рдирддреЗ рд╣реИрдВ рд╕реЙрд▓реНрдпреВрд╢рди ред


Problem:- Text Wrap Hackerrank Solution In Python 3


You are given a string S and width W.

Your task is to wrap the string into a paragraph of width W.


Function Description

Complete the wrap function in the editor below.

wrap has the following parameters:

  • string string: a long string
  • int max_width: the width to wrap to

 

Returns

  • string: a single string with newline characters ('\n') where the breaks should be

Input Format

The first line contains a string, String .

The second line contains the width,max width.


Constraints

  • 0 < len(string) < 1000
  • 0 < max width < len(string)

Sample Input 0


ABCDEFGHIJKLIMNOQRSTUVWXYZ

4


Sample Output 0


ABCD

EFGH

IJKL

IMNO

QRST

UVWX

YZ



Solution


import textwrap

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

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


Other Articles 



DISCLAIMER:-

The above hole problem statement is given by hackerrank.com but the solution is generated by the Apna Hindi Tech authority if any of the query regarding this post or website fill the following contact form.

......Thank YouЁЯШК......

рдпрд╣ рднреА рдкрдврд╝реЗрдВ

2 comments

Post a Comment