Text Wrap

Sort by

recency

|

1875 Discussions

|

  • + 0 comments

    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)

  • + 0 comments

    Solution rs_str = "" counter = abs(len(string)/max_width)

    while counter > -1: rs_str += string[:max_width]+'\n' string = string.removeprefix(string[:max_width]) counter -= 1

    return rs_str `

  • + 0 comments

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

  • + 0 comments

    def wrap(string, max_width): i = 0 wrapped = '' while i < len(string): wrapped = wrapped + string[i] i = i + 1 if i % max_width == 0: wrapped = wrapped + '\n'
    return wrapped

  • + 1 comment

    def wrap(string, max_width): count = 0 y = "" for i in string:

        if count == max_width:
            y = y + "\n"
            count = 0
    
        y += i
        count += 1
    
    return y