Lesson 5 of 30

Lesson 05 — Choices with if

Title: Teach Python to make simple decisions

Description: Use if, elif, and else to check answers, ages, scores, and secret words.

Why it matters for kids: Games need decisions: win or try again, open a door or keep it closed.


1. The first choice

pythonpython
weather = "rainy"

if weather == "rainy":
    print("Take an umbrella.")
else:
    print("Enjoy the sunshine.")

Python uses indentation to know what belongs inside the if.


2. Check a quiz answer

pythonpython
answer = input("What is 3 + 4? ")

if answer == "7":
    print("Correct!")
else:
    print("Try again later.")

3. More than two choices

pythonpython
score = 85

if score >= 90:
    print("Gold star!")
elif score >= 70:
    print("Silver star!")
else:
    print("Keep practicing.")

4. Secret door

pythonpython
secret_word = input("Say the magic word: ")

if secret_word == "please":
    print("The door opens.")
else:
    print("The door stays closed.")

5. Easy examples

pythonpython
age = 8

if age >= 7:
    print("You can join the coding club.")
else:
    print("You can join the junior club.")
pythonpython
has_ticket = True

if has_ticket:
    print("Welcome to the movie.")
else:
    print("Please buy a ticket.")
pythonpython
favorite_color = "green"

if favorite_color == "green":
    print("You picked a forest color.")
elif favorite_color == "blue":
    print("You picked an ocean color.")
else:
    print("That color is cool too.")

6. Mini challenge

Click each example to open it.

Example 1

Check if score == 10.

Example 2

Check if age is 7 or more.

Example 3

Check if a password equals "cat".

Example 4

Print one message for rainy weather.

Example 5

Print one message for sunny weather.

Example 6

Use else for a wrong answer.

Example 7

Use elif for a second color.

Example 8

Check if a number is bigger than 5.

Example 9

Check if a toy count is zero.

Example 10

Make a secret door with one correct word.