Step 6 – Solve the riddle
There's a riddle on the door. We need to solve it to get to the next bit of the escape room.
This is a classic riddle. We just need the player to say "friend" to open the door...
The first problem is that we haven't added the code to ask the player what they want to do next. This needs to go in the ELSE block
Add a print and an input line to the ELSE block
This will stop the program going wild at least some of the time
Next we need to deal with the player solving the riddle.
Remember, to solve the riddle they just need to type in "friend"
Add a new elif section in the while loop you were just working on. This deals with what happens if the user types in "friend"
- IMPORTANT: make sure you include the line:
move_on = True lineIf they say "friend" they've solved the riddle, so we need to move on
- Run your program to test it
Make sure you test all the possible things in the last section:
- "open"
- "look"
- something random (try "run")
- friend
That should test everything possible in the last section
The code should work as long as the player types in "friend".
But what if they type "say friend"? That seems a reasonable thing for them to do.
We can manage this by adding an or to the elif line. You can do this to any if or elif line – or to a while loop line. You can add as many or's as you want, but it gets tricky if you have too many!
Change the elif line to the second screenshot
- Run your program to test it
Hopefully everything works...
Now do: you could add a hint to help the player. Look back at step 6 if you need a reminder on how to do this.
That's it for Part 2. What do you think should happen next?
Then click here to move on to Part 3
The riddle, of course, is the way that Gandalf, Frodo and co enter the Mines of Moria in The Lord of the Rings. Maybe you've seen the movie? Or played the Lego video game? Or even read the book?