The Echo Finder
In the last lesson, we replaced one awkward rune in the gate sign. Now Hoppy steps into the echo hall before the crystal arch, and a message appears on the wall: "Listen for the echo near the crystal arch".
This time, Hoppy does not want to edit the text. The next move is to track one clue word inside it. To follow echo, it helps to know where that word is hiding in the sentence. This lesson is about searching the clue and getting its coordinate.
First, watch a clue word turn into a number
The key experience here is seeing something new for the first time: a string does not only hold text. It can also give you a position when you search inside it. One quick search, and a clear number appears on the screen.
clue_note = "Find the bell near the bridge"
print("Clue:", clue_note)
bell_position = clue_note.find("bell")
print("Bell starts at:", bell_position)
When you run it, you will see 15. That number does not mean “echo has 15 letters.” It means the text echo starts at position 15 inside this clue.
Use find() to search inside a string
find() looks through a string for the target text you give it. If it finds that target, it returns the position where the target starts. If it does not find it, it returns -1.
You do not need an if-statement yet. Just build the core instinct first: when a line of text is already readable, but you want to keep working from one word inside it, find() can turn that word into a useful clue coordinate.
The starter already shows the original sentence and the output lines. The real move you need to add is the line that creates echo_position.
Use clue_note.find("echo") to search for that clue word, and save the result in echo_position.
First look at the sentence, then look at the position result. The feeling to keep is: a word inside a string is something I can actively search for and locate.
If find() cannot find the target, it returns -1. That simply means “it did not appear.” For this lesson, you only need to recognize that signal. We do not need to turn it into branching logic yet.
Suggested SolutionExpandCollapse
clue_note = "Listen for the echo near the crystal arch"
print("Clue:", clue_note)
echo_position = clue_note.find("echo")
print("Echo starts at:", echo_position)Advanced TipsWant more? Click to expandClick to collapse
Programmers would say that find() returns the starting position of the target text inside a string. You only need that name lightly right now. The bigger shift is the new feeling: strings are not only for changing. They are also things you can search.
Later, when you have a sentence and want to keep observing or working from one word inside it, you can ask yourself: should I find where that word is first? For now, just get comfortable with this one search move.