🤖 Python Grade 5 · session 5 of 44 · 60 minutes · 🎁 free with an account

Decisions: if, elif and else

Now Bolt can think! With if and else, your program chooses what to do. Build a secret door, a quiz that keeps score and a robot that knows odd from even.

Illustration of a cute pastel robot dancing
Illustration: andremsdesign / Pixabay

A complete lesson · 60 minutes

Teach it, see it, practise it, all on this page.

Open this page with your learner and work down it, or press Teach this lesson to go through it one step at a time on a big screen. Every section has something to do.

  1. Warm-up3 min
  2. Warm-up games5 min
  3. if and else: two doors9 min
  4. Many doors with elif9 min
  5. and, or, and keeping score9 min
  6. The secret door7 min
  7. Three-question quiz7 min
  8. Rock, paper, scissors judge5 min
  9. Quiz5 min
  10. Set the after-class project1 min

By the end you can

  • Compare with ==, >, < and !=
  • Choose between two paths with if and else
  • Choose among many paths with elif
  • Build a quiz that keeps score

Before you start

  • Lesson 3: variables
  • Lesson 4: input() and int()

Have ready

  • This page
  • Three quiz questions in your head

Grade 5 · ages 10 and 11 · no experience needed

Warm-up · think first

If it's raining, take an umbrella. Otherwise, take a cap. It's sunny. What do you take?

Show the answer

A cap. You only do one of the two. That's exactly how if and else work.

Teacher tip: Ask for another if-otherwise rule from daily life.

More warm-ups for every class →

🎮 Warm-up games · 5 quick games

Play with Bolt the robot

Five minutes with Bolt the robot. Vote, say why, then show the answer.

  1. Which is not a true or false question? (Is 5 bigger than 3? · Is it raining? · How old are you? · Is your name Om?)
    Answer: "How old are you?" has a number for an answer. The others are simply yes or no, which is what if needs.
  2. Would you rather open a door with a password, or with a riddle? (A password · A riddle)
    Answer: Both work the same way in Python: compare the answer to the right one.
  3. When a program reaches if and else, it runs both paths. (Always · Sometimes · Never)
    Answer: Never — Never. It runs exactly one of them, and then carries on.
  4. Which number makes this true: it's bigger than 5, smaller than 8, and even?
    Answer: 6. 7 is odd, so only 6 fits.
  5. What decisions does a game make while you're playing?
    Answer: Did you hit the wall? Is the score high enough? Any lives left? Every one is an if.

Three levels, like a real engineer

Use it. Tweak it. Build it.

First use what the lesson shows exactly as it is, then change one key thing and see what happens, then make your own.

  1. 🔒

    Level 1 · Use it

    Run Score Keeper

    Run the finished Score Keeper quiz exactly as written: answer its questions and watch the score change after each if, elif, and else choice. Do not edit any code yet.

  2. 🔧

    Level 2 · Tweak it

    Tweak Quiz Points

    In Score Keeper, change the correct-answer points from 1 to 3, and change one quiz answer from '4' to '5'. Predict what the score will do, then run it and check.

  3. 🛠️

    Level 3 · Build it

    Build Your Quiz

    Make your own three-question quiz from scratch using if, elif, and else to check answers and add points. Test it with a friend and see if the score ends correctly.

Part 1 of 3 · learn, see, practise

if and else: two doors

Listen to this part

I'm at two doors! If the answer's true, I go through the first. Otherwise, I take the else door. The two dots and the spaces matter!

== asks "are these the same?". A single = puts something in a box.

if needs a colon at the end of the line, and the next line is moved in by 4 spaces.

else runs when the if question is false.

🧑‍🏫 Teacher: type this live with the class

The secret door

  1. password = input("Password? ")

    Put open in the Input box. Say: this is the question.

  2. if password == "open":

    Two equals signs ask: are they the same? Point at the colon. Press Enter and see the indent.

  3. print("Come in!")

    Four spaces in. This line only runs if it's true.

  4. else:

    Back to the left. else also has a colon.

  5. print("Go away!")

    Run it, then change the Input box to a wrong password.

Type here

▶ Output

(nothing is printed)

📦 Memory boxes

No variables yet
Example: run it, then change it

▶ Output

Age? 11
You can ride the big slide!

📦 Memory boxes

age11int

Try 9, 10 and 11 in the Input box. What does >= mean?

Puzzle break: which door?

Be the computer: ask the question, then walk through one door only.

  1. Puzzle 1: say what happens before you run it
  2. Puzzle 2: fill the gap
  3. Puzzle 3: find the bug

Practise it

Start with the warm-up and go as far as you can. The stretch questions are meant to be hard.

Warm-up

1.1 Ask for a colour. If it's blue, print Same!, otherwise print Different!

Task 1.1

▶ Output

(nothing is printed)

📦 Memory boxes

No variables yet
🧑‍🏫 Model answer (for the teacher)

Teacher eyes only: hide the answers before you share your screen.

The answer green = the 5 lines the student writes

c = input("Colour? ")if c == "blue":    print("Same!")else:    print("Different!")

What it prints when they type blue

Colour? blue
Same!

What ✓ Check looks for

  • When they type blue, the output includes Same!
  • When they type red, the output includes Different!
Warm-up

1.2 Fix the bug: the if line is missing something.

Task 1.2

▶ Output

Line 2: SyntaxError: expected ':'

📦 Memory boxes

No variables yet
🧑‍🏫 Model answer (for the teacher)

Teacher eyes only: hide the answers before you share your screen.

The answer green = the 1 line the student writes

score = 10if score == 10:    print("Perfect")

What it prints

Perfect

What ✓ Check looks for

  • it prints exactly:
    Perfect
Core

1.3 Fix the two bugs: = should be ==, and the print is not moved in.

Task 1.3

▶ Output

Line 2: SyntaxError: expected ':'

📦 Memory boxes

No variables yet
🧑‍🏫 Model answer (for the teacher)

Teacher eyes only: hide the answers before you share your screen.

The answer green = the 1 line the student writes

x = 5if x == 5:    print("Five")

What it prints

Five

What ✓ Check looks for

  • it prints exactly:
    Five
Core

1.4 Ask for a number. If it's bigger than 100, print Big. Otherwise print Small.

Task 1.4

▶ Output

(nothing is printed)

📦 Memory boxes

No variables yet
🧑‍🏫 Model answer (for the teacher)

Teacher eyes only: hide the answers before you share your screen.

The answer green = the 5 lines the student writes

n = int(input("Number? "))if n > 100:    print("Big")else:    print("Small")

What it prints when they type 500

Number? 500
Big

What ✓ Check looks for

  • When they type 500, the output includes Big
  • When they type 5, the output includes Small
  • When they type 100, the output includes Small
Stretch 🔥

1.5 Odd or even? Ask for a number and print Even or Odd, using % 2.

Task 1.5

▶ Output

(nothing is printed)

📦 Memory boxes

No variables yet
🧑‍🏫 Model answer (for the teacher)

Teacher eyes only: hide the answers before you share your screen.

The answer green = the 5 lines the student writes

n = int(input("Number? "))if n % 2 == 0:    print("Even")else:    print("Odd")

What it prints when they type 8

Number? 8
Even

What ✓ Check looks for

  • When they type 8, the output includes Even
  • When they type 7, the output includes Odd
  • In the code: Use % 2.

🎁 Free for a year

Make a free account to open the rest of this lesson

Every new account opens every lesson of every course free for a whole year: no payment, no card, nothing to cancel.

Unlocking the rest of this lesson gives you:

  • Part 2: Many doors with elif, with practice at three levels
  • Part 3: and, or, and keeping score, with practice at three levels
  • Class activity 1: The secret door
  • Class activity 2: Three-question quiz
  • Class activity 3: Rock, paper, scissors judge
  • A 8-question quiz
  • After-class project: Adventure story game
  • Homework and a printable practice sheet with answers
  • Teach mode and the minute-by-minute teacher's plan

It takes a minute. Anyone under 13 signs up with a parent. The first 2 lessons of every course, every game and all maths practice stay free.

FAQ

Decisions: if, elif and else: questions

What is the difference between if and elif?

if starts the decision. elif adds another question, and is only checked if the ones above were false.

Why does Python need spaces in front of a line?

The spaces show which lines belong to the if. Python uses them the way a list uses bullet points.

What does != mean?

It means not equal. 5 != 3 is true.

Start a conversation

Want a teacher to take this class?

Tell us the learner's age and level. A teacher from our network teaches with these lessons; we confirm timing and price first.

  • Tell us the learner’s age or grade and goals
  • We’ll suggest a suitable class or learning path
  • We’ll confirm format, timing and fees with a parent or guardian

For a child’s class, please have a parent or guardian send the enquiry. Avoid sharing passwords or sensitive personal details.

We’ll use your details only to respond to this request.

Chat on WhatsApp
Esc

Try