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 &, < with <, > with >, a double quote with " and a single quote with '.
Each character must be escaped exactly once: the text a < b must become a &lt; b, so the order of replacements matters.
What Check tests
- Tags are escaped
- Quotes are escaped
- An ampersand is escaped exactly once
- 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.