Word wrap
Write wrap(text, width) that text into lines no longer than width characters, breaking only at spaces, greedily fitting as many words per line as possible. Words longer than width go on their own line unbroken. Return the of lines.
Examples
wrap("keep calm and write more code", 10) → ["keep calm", "and write", "more code"]Exercise
4 checksWord wrap
def wrap(text, width):
...
for line in wrap("keep calm and write more code", 10):
print(f"|{line:<10}|")
Press Run to try your code, then Check answer to grade it.