Command Palette

Search for a command to run...

Hectal
Phase 10: Safety and Security (Defensive)
LLM Engineering · Exercise 1 of 5Next
Intermediate

Escape a model reply for HTML

A model reply is about to be inserted into a web page. Write escape_html(text) that returns the text with these five characters replaced: & with &amp;, < with &lt;, > with &gt;, a double quote with &quot; and a single quote with &#39;.

Each character must be escaped exactly once: the text a &lt; b must become a &amp;lt; b, so the order of replacements matters.

What Check tests

  1. Tags are escaped
  2. Quotes are escaped
  3. An ampersand is escaped exactly once
  4. Plain text is unchanged

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.