-1

How to add new line in python. for example, I would like to print the rest of a sentence in a new line. but instead of putting "\n", I will automate it to type to a new line for every six words.

Morse code translator

enter image description here

Dave
  • 3,073
  • 7
  • 20
  • 33
  • Possible duplicate of [How would I specify a new line in Python?](https://stackoverflow.com/questions/11497376/how-would-i-specify-a-new-line-in-python) – Felix Lemke Oct 25 '18 at 06:54
  • They know how to print into a new line, it's not a duplicate nor has anything to do with it. – Purple Ice Oct 25 '18 at 10:22

1 Answers1

0

sth like:

def wrapper(words, n):
        to_print = ''
        for i in range(0, len(words.split()), n):
            to_print += ' '.join(words.split()[i:i+n]) + '\n'
        return to_print

and result is:

print(wrapper('a b c d e f g h i j k l m n o p r s t u w x y z', 6))

a b c d e f
g h i j k l
m n o p r s
t u w x y z
Macio
  • 104
  • 6