HackerRank- Python Text Wrap




Problem 9:

You are given a string S and width W .
Your task is to wrap the string into a paragraph of width W.



  1. import textwrap
  2. def wrap(string, max_width):
  3. for i in range(0,len(string)+1,max_width):
  4. result=string[i:i+max_width]
  5. if len(result)==max_width:
  6. print(result)
  7. else:
  8. return(result)
  9. if __name__ == '__main__':
  10. string, max_width = input(), int(input())
  11. result = wrap(string, max_width)
  12. print(result)




codesadda.com

Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube