The Masked Word
In the last lesson, we bound loose word pieces back into a full clue. Now Hoppy finds a gate sign beside the mossy gate. It is almost ready to use, except for one temporary rune in the middle: "Meet me @ the mossy gate".
If Hoppy needs to hand this clue to the gate sprite right away, the @ feels like a small mask in the way. The easiest move is not to rewrite the whole line or split it apart again. It is to replace that one tiny rune.
First, watch how one tiny spot gets cleaned up
Don’t worry about the method name yet. Just look at the two output lines: the first one keeps the old version, and the second one changes only that one small part in the middle.
masked_sign = "m00n arch"
print("Before:", masked_sign)
clean_sign = masked_sign.replace("0", "o")
print("After:", clean_sign)
Almost the whole sentence stays put. The only thing that changes is @. This is not a big rewrite spell. It is a tiny repair: swap out the bit that is getting in the way, and the clue becomes usable again.
Use replace() for that one quick fix
When a sentence is basically readable, but one old word, noisy character, or small fragment should not stay there, replace() is a very handy move. It does not ask you to rewrite the whole thing. It lets you repair the exact bit that needs help.
You can read masked_note.replace("@", "at") like this: in this clue, when you see @, swap it for at. Hoppy does not need to copy the whole note again, and neither do you. Fix this spot, and you are done.
The starter already shows the original string and the two output lines. The only line you need to change is the one that creates clean_note.
Use replace() for this one replacement so clean_note becomes a version of the clue you would actually want to use.
Look at the line with @ first, then the cleaned version after it. The thing you are checking is not “Did I memorize the method name?” It is “Did I fix the small part that was off?”
Because this lesson is really about seeing the replacement happen. When the original stays on screen, you can instantly tell which small piece changed.
Suggested SolutionExpandCollapse
masked_note = "Meet me @ the mossy gate"
print("Before:", masked_note)
clean_note = masked_note.replace("@", "at")
print("After:", clean_note)Advanced TipsWant more? Click to expandClick to collapse
Programmers would say that replace() swaps old content inside a string for new content. You only need the name lightly for now. The move matters more: when one little piece is in the way, you do not always need to split everything up or rewrite the whole sentence. You can replace that piece directly.
Sometimes you will replace an old word with a new one. Sometimes you will replace a noisy character, or even replace a fragment with an empty string so it disappears. More complex replacement patterns can wait. This lesson is just about getting comfortable with this small repair move.