Command Palette

Search for a command to run...

Hectal
Phase 3: Prompting as Engineering
LLM Engineering · Exercise 2 of 6 PreviousNext
Beginner

Escape and wrap untrusted text

Write escape(text) that replaces & with &amp;, < with &lt; and > with &gt; (in that order).

Write wrap(tag, text) that returns <tag>, the escaped text and </tag> on three separate lines.

What Check tests

  1. Plain text is unchanged
  2. < and > are escaped
  3. & is escaped first, so no double escaping
  4. wrap puts the escaped text between the tags
  5. The wrapped text never contains a second closing tag

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

main.py
Sign in to run your code.

Output

Press Run to see what your program prints.