Python for Humans · Draft v0.1 · Oct 27, 2026 · Draft position: chapter 2 · First draft.

Making Decisions

You'll build
Teach Python to make choices and create your own adventure game.

In the last chapter, we built programs that could ask questions, remember answers, and even tell ridiculous stories.

But our programs always followed the same instructions, regardless of what we told them.

What if we could change that? What if Python could choose what to do based on our answers?

Making a Choice

Remember our little robot? Let's ask it a very important question.

answer = input("Do you like pizza? (yes/no) ")

if answer == "yes":
    print("Excellent! Pizza is delicious.")
else:
    print("More pizza for me!")

Click Run and answer yes. Now run it again and answer no. Did you notice what happened? Our robot responded differently depending on what you typed! That's because we've introduced something new: an if statement.

Take another look at this part of our program:

if answer == "yes":
    print("Excellent! Pizza is delicious.")

The if tells Python to check whether something is true. In this case, we're checking whether the value stored in answer equals "yes". Notice that we're using two equal signs, ==, instead of one.

Previously, we used a single equal sign, =, to assign values to variables. But two equal signs, ==, ask Python whether two values are equal.

If the answer is yes, Python runs the indented line underneath. But what if the answer is no? That's where else comes in:

else:
    print("More pizza for me!")

The else tells Python what to do when the condition isn't true.

Try it yourself: Run the program above and enter maybe. Which message do you get? Now try Yes with a capital Y.

Python is very literal! It treats "yes" and "Yes" as different strings. And since our program only checks for "yes", every other answer leads to the else message.

Mind the Indentation

There's something else new in our program. Notice how the print() lines are indented underneath if and else. In Python, those spaces matter!

Indentation tells Python which instructions belong together. The indented code below an if runs only when its condition is true. The colon : at the end of the if and else lines tells Python that an indented block of code is coming next.

In the box below, remove all four spaces before print("Excellent! Pizza is delicious."), then click Run. You'll get an error! Python needs an indented block after if.

answer = input("Do you like pizza? (yes/no) ")

if answer == "yes":
    print("Excellent! Pizza is delicious.")
else:
    print("More pizza for me!")

Add the four spaces back and run it again to check that it works.

Now add this line at the very end of the program, with no spaces before it:

print("Thanks for answering!")

Before you run it, predict: will this message appear when you answer yes, no, or both? Try both answers to check.

Because the new line isn't indented, it sits outside the if and else blocks. Python runs it after either choice.

More Than Two Choices

Our robot can now choose between two possibilities. But what if we want to give it more options?

Imagine a robot that recommends something to do based on the weather.

weather = input("What's the weather like? ")

if weather == "sunny":
    print("Let's go to the beach!")
elif weather == "rainy":
    print("Let's stay inside and read.")
elif weather == "snowy":
    print("Time for a snowball fight!")
else:
    print("Sounds like interesting weather!")

Try running the program with different answers.

We have another new word here: elif. It's short for else if.

Python starts at the top and checks each condition in order. When it finds one that's true, it runs the corresponding instructions and skips the remaining choices.

If none of the conditions match, it runs the else block.

This means our programs can now choose between several possible outcomes!

Your turn: Add another kind of weather. What should your robot recommend when it's windy? Or foggy? Or raining meatballs?

Build Your Own Adventure

Now that our programs can make decisions, let's put that new ability to use.

Have you ever played a choose-your-own-adventure game? You read a story, make a decision, and discover what happens next. Different choices lead to different adventures.

We can build one with Python!

Let's start with a mysterious castle.

print("Welcome to the Mysterious Castle!")
print("You find yourself standing in a dark hallway.")
print("Ahead are two doors: one red and one blue.")

door = input("Which door do you choose? (red/blue) ")

if door == "red":
    print("You discover a sleeping dragon!")
elif door == "blue":
    print("You find a chest full of treasure!")
else:
    print("You decide to stay in the hallway. Probably safer.")

Run the program and choose the red door.

Now try the blue door.

We have two completely different outcomes depending on what the player chooses. And we accomplished that with just a few lines of Python!

But our adventure is over almost as soon as it begins.

What if we wanted to keep going?

Another Decision

Let's make our adventure a little more interesting.

This time, choosing the red door leads to another decision.

print("Welcome to the Mysterious Castle!")
print("Ahead are two doors: one red and one blue.")

door = input("Which door do you choose? (red/blue) ")

if door == "red":
    print("You discover a sleeping dragon!")
    action = input("Do you sneak or shout? ")

    if action == "sneak":
        print("You tiptoe past the dragon and steal its treasure!")
    else:
        print("The dragon wakes up. It looks hungry!")

elif door == "blue":
    print("You find a chest full of treasure!")

else:
    print("You decide to go home instead.")

Now we have a story with several possible outcomes!

Notice that there's an if statement inside another if statement.

This is called a nested conditional. It's just a way of making one decision lead to another.

If the player chooses the red door, we ask another question. But if they choose the blue door, we skip that question entirely.

Look closely at the indentation. The second if is indented inside the first one, and its print() lines are indented even further.

That's how Python knows which instructions belong to which decision.

Try choosing different paths and see what happens.

Your Turn: Create an Adventure Game

You've learned enough to build your own choose-your-own-adventure game.

It could take place in a haunted house, an underwater city, on another planet, or anywhere else you can imagine.

Start with a setting, give the player a choice, and use if, elif, and else to decide what happens next.

Here's a place to begin:

print("Welcome to my adventure!")

choice = input("Which path will you take? (left/right) ")

if choice == "left":
    print("Something mysterious happens!")
else:
    print("A different adventure begins!")

Create at least two different endings, then add a second decision inside one path. You can extend the castle instead: give the blue door its own question, or let the player try to befriend the dragon.

Before you run it, write down the answers that should reach each ending. Try each path and check whether it reaches the ending you expected.

Don't worry if things don't work the first time. Experiment, make mistakes, and borrow ideas from the examples above.

The story is yours to tell!

What's Next?

Our programs can now make decisions based on the information we give them. With if, elif, and else, we've gone from programs that always follow the same path to ones with different possible outcomes.

And we've used that ability to build our first adventure game!

But there's still one problem.

Every time our adventure ends, the program stops. If we want to play again, we have to start it all over.

What if we wanted our program to keep running? What if we wanted to give the player another chance without having to repeat our code?

That's what we'll explore next.