Standard library · 17 / 17 Exercise Medium

Fitting text to a width

Objective

The textwrap module formats paragraphs: it splits a text into lines of a maximum width and can shorten it by adding an ellipsis.

Instructions

  • Read an integer width (at least 10) and a line of text.
  • Show the text split into lines of at most width characters with textwrap.fill(text, width).
  • Show a line with three hyphens: ---.
  • Show the text shortened to width characters with textwrap.shorten(text, width, placeholder="...").
Input
20
una frase de ejemplo para ajustar a un ancho fijo
Output
una frase de ejemplo
para ajustar a un
ancho fijo
---
una frase de...

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise