concept right cave in category raspberry pi

This is an excerpt from Manning's book Hello Raspberry Pi!: Python programming for kids and other beginners.
If Raspi decides to go into the right cave, he’ll need to decide whether to climb down into a hole using a rope or walk toward what appears to be a torch. After walking toward the torch, Raspi will enter a cave full of crystals. The crystal cave sounds promising, but unfortunately a crystal will fall from the ceiling, ending Raspi’s life (game over). Alternatively, if Raspi uses the rope and goes down the hole, he’ll find himself in the dragon’s lair with a final choice: whether to fight the dragon or go into a dark room. If Raspi fights the dragon, the dragon will eat him; but if Raspi heads toward the dark room, he’ll discover that it’s filled with thousands of gold coins, rubies, and diamonds. Raspi is rich and very much alive!
In this game, Raspi has two initial cave choices: left or right. Programming the right cave is similar to the left cave. Once again, you’ll use the map and flow diagram as your guides. Let’s add the logic for the right cave, which starts with the user finding a hole in the ground (see figure 5.8).
Figure 5.8. The right cave consists of a series of decisions. One wrong move, and certain death awaits Raspi. If the user makes the right choices, Raspi will find the treasure. The code uses if/elif/else statements and functions. See the code files for chapter 5 for examples of the functions.
![]()
The right cave uses logic similar to that of the left cave. You’ll use if, elif, and else statements to handle all the possible choices. As with the left cave, notice that you indent the if/elif/else statements under the other if statements to create the logic you desire. Nesting is the name given to indenting one set of if statements inside another. The technique of nesting if statements is useful when you have logic that you want executed only if a prior condition is True. In this case, you only want to give the user the choice of fighting the dragon if they have already decided to climb down into the hole using the rope. The logic now matches the flow diagram for the game.