-->

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