We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
def wrap(string, max_width):
snew=''
l=[]
for i in range(len(string)):
if i>0 and i%max_width==0:
l.append(snew)
snew =''
snew=snew+string[i]
l.append(snew)
return '\n'.join(l)
if name == 'main':
string, max_width = input(), int(input())
result = wrap(string, max_width)
print(result)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Text Wrap
You are viewing a single comment's thread. Return to all comments →
import textwrap
def wrap(string, max_width): snew='' l=[] for i in range(len(string)): if i>0 and i%max_width==0: l.append(snew) snew ='' snew=snew+string[i] l.append(snew) return '\n'.join(l)
if name == 'main': string, max_width = input(), int(input()) result = wrap(string, max_width) print(result)