Objective
Create a Python program with a context manager written as a generator function and the @contextmanager decorator from the contextlib module.
Instructions
- Define
frame(title): a function with@contextmanagerthat, before theyield, shows a line of=, another with| title |and another of=. The number of signs is the length of the title plus 4. - The
yieldreturns the length of the title. After theyield(insidefinally, so that it always runs) show a line of-with the same length. - Read an integer
nand thenntexts. For each one usewith frame(text) as length, and inside showCharacters: lengthand the text reversed.
2
hola
ab
========
| hola |
========
Characters: 4
aloh
--------
======
| ab |
======
Characters: 2
ba
------
Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.
Start exercise