Search⌘ K
AI Features

Project: Interactive Adventure Story

Explore how to build your own interactive adventure story in Python by using input to gather player choices and conditional statements to drive the plot. Learn to implement loops for replayability, track scores, and craft multiple endings. This project helps you apply basic syntax and programming concepts in a fun, creative context.

Welcome to your first big Python project! It’s time to use everything you’ve learned to create your very own interactive adventure story.

In this project, you’ll build a short, fun game in which the user makes choices and experiences different outcomes based on those decisions.

Goals

You’ll aim to:

  • Take user input (input()) to interact with the player.

  • Use conditional logic (if, elif, else) to branch your story.

  • Use loops (while) for game flow and continuity.

Project steps

Here is the general breakdown of a project that we will discuss in the steps below:

  • Begin with a friendly welcome and ask the player for their name to personalize the story.

  • Ask the player to choose between two paths (like entering a forest or walking along its edge). This sets the direction for the rest of the story.

  • Use if, elif, and else statements to show different parts of the story based on the player’s choice.

  • Within each story branch, ask another question to add interaction and track a score.

  • End the story with a message that reflects the player’s decisions.

  • Replay the story using a while loop so they can explore different outcomes.

Step 1: Story setup

Start the game by asking for the player’s name and setting the scene. Use input() and print() to make the story’s start feel personal.

name = input("Welcome, adventurer! What is your name? ")
print(f"Greetings, {name}! You stand at the entrance of a mysterious forest, hearing rustling leaves and distant, magical sounds.")
print("Do you choose to go into the forest, or walk along its edge?")
Enter your name

Step 2: First decision

Ask the player what they want to do next using input(). Store their choice in a variable so you can respond to it later.

choice = input("Type 'enter' to bravely venture into the forest, or 'walk' to take the scenic route along its edge: ")
Enter your name and choice

Step 3: Branching paths (Playful responses)

Use if, elif, and else to respond to their decision with different messages. Make the responses fun to keep the story engaging.

if choice == "enter":
    print("Brave choice! You step boldly into the shadows and discover a glittering sword lying dramatically on the ground—how convenient!")
elif choice == "walk":
    print("Taking the scenic route, eh? You casually stroll along the forest's edge, humming a tune until a wise old man interrupts your concert.")
else:
    print("Indecisive adventurers don't get far! You take an unplanned nap. Perhaps adventure will find you instead?")
Branching paths based on your choice

Step 4: Add another decision

If the player entered the forest, ask them another question. Add a score variable to track their bravery points based on what they do.

score = 0
if choice == "enter":
    action = input("Do you pick up the sword? (yes/no): ")
    if action == "yes":
        score += 10
        print(f"The sword feels powerful in your hands. You're ready for adventure! You've earned 10 bravery points! Total Score: {score}")
    else:
        print(f"You leave the sword and continue deeper into the forest, feeling slightly unprepared. Current Score: {score}")
Add another decision based on your choice

Step 5: Branching multiple endings

If the player chooses to walk, ask if they want advice from a wise old man. Show different endings depending on what they say.

if choice == "walk":
    wisdom = input("The old man offers wisdom. Do you accept? (yes/no): ")
    if wisdom == "yes":
        print("You gain insightful knowledge about the forest. A wise decision! 🧙‍♂️")
    else:
        print("You politely decline, missing out on sage advice. Perhaps bravery is your strength!")
Branching multiple ending

 Project tips

  • Make each choice clear and impactful.

  • Use descriptive print statements to paint a vivid scene.

  • Experiment with nested if statements to add depth.

Mini challenge

  • Add another layer of decisions to your story.

  • Use a loop (while) to allow the user to replay the game when it ends with interactive replay prompts:

play_again = "yes"
while play_again == "yes":
    # (Your adventure story here)

    play_again = input("Adventure complete! Would you dare to embark again? (yes/no): ")
    if play_again.lower() == "yes":
        print("The forest awaits your return, bold adventurer!")
    else:
        print("Farewell, traveler! Until next time!")
Mini challenge on decision

If you’re stuck, click the “Show Solution” button.

Go further

  • Expand your scoring system based on more intricate choices.

  • Create additional unique endings based on the player's decisions.

Awesome. You've got this! Craft your interactive tale and bring your adventure to life with Python.