Search⌘ K
AI Features

Challenge: Add Layers to Your Adventure

Explore how to deepen your choose-your-own-adventure game by adding multiple layers of choices using nested if-elif-else statements. This lesson helps you enhance your Python skills by building reusable logic structures and handling user input for varied story outcomes within a single function.

We'll cover the following...

You’re building a choose-your-own-adventure game where the player’s choices decide what happens next.

You are given a starting version of the game. Your job is to add more choices and outcomes to make the story deeper and more interesting.


What’s Already There

The starter code already:

  • Defines a function called jungle_adventure()

  • Asks the player to choose a path:

    • "river"

    • "mountain"

    • "jungle"

  • Prints one outcome based on that choice

  • Calls the function so the game runs


Your Task

Modify the function so that:

  1. At least one path asks the player a second question

    1. For example:

  2. That second decision should have at least three possible choices

    1. Each choice should lead to a different printed outcome

  3. Use if, elif, and else to handle each choice


Example Flow (Conceptual)

You don’t need to copy this, it’s just to show the idea:

  • Player chooses "river"

  • Player is asked what to do next

  • Different actions lead to different endings


Rules

  • Keep everything inside the jungle_adventure() function

  • Use input() to get the player’s choices

  • Use nested if / elif / else blocks

  • Make sure the function still runs when the program starts


💡 Tips

  • You can store each choice in a variable (like path or action)

  • Don’t worry about spelling mistakes, an else case can handle unexpected input

  • The goal is clear logic, not a perfect story

# Modify the function below by adding more layers to make the story your own!
def jungle_adventure():
    # Ask the user to choose between two paths
    path = input("You find two paths: one goes to a river, the other to a mountain. Where do you go? ")

    # Check what the user typed and respond accordingly
    if path == "river":
        print("You swim with dolphins!")
    elif path == "mountain":
        print("You find an ancient temple!")
    else:
        # If the user typed something else, give this outcome
        print("You wander into the jungle and get lost.")

# Start the jungle adventure by calling the function
jungle_adventure()
Introducing the idea of nested decisions for more story complexity