Apna Hindi Tech Website Computer science рдХे Students рдФрд░ Technology рдХे рдмाрд░े рдоें рдЬाрдирдХाрд░ी рд░рдЦрдиे рд╡ाрд▓े рд▓ोрдЧों рдХे рд▓िрдП рдмрд╣ुрдд рд▓ाрднрджाрдпрдХ Web site рд╣ै।
рд╣рдоाрд░ी Website Apna Hindi Tech рдкрд░ Free рдоें Python Programming language рд╣िंрджी рдоें рд╕िрдЦाрдИ рдЬाрддी рд╣ै рдФрд░ рджुрдиिрдпा рдоें рдЬो рд▓ेрдЯेрд╕्рдЯ рдЯेрдХ्рдиोрд▓ॉрдЬी(Technology) рд╣ै рдЙрд╕рдХे рдмाрд░े рдоें рд╡िрд╕्рддाрд░ рд╕े рдмрддाрдпा рдЬाрддा рд╣ै।
рджोрд╕्рддों рд╣рдордиे рдЕрдкрдиी рд╡ेрдмрд╕ाрдЗрдЯ Apna Hindi Tech рдкрд░ Python Programming рд╕े рд░िрд▓ेрдЯेрдб рдмрд╣ुрдд рд╕ाрд░े Softwares рдмрдиाрдиा рднी рд╕िрдЦाрдпा рд╣ै рд╡ो рднी рдЕрдкрдиी рднाрд╖ा рд╣िंрджी рдоें।
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(string, max_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
Nice
ReplyDeleteVery simple code
ReplyDelete