🤖 Python Grade 5 · session 5 of 12 · 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.
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.
- Warm-up3 min
- Warm-up games5 min
- if and else: two doors9 min
- Many doors with elif9 min
- and, or, and keeping score9 min
- The secret door7 min
- Three-question quiz7 min
- Rock, paper, scissors judge5 min
- Quiz5 min
- 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.
🎮 Warm-up games · 5 quick games
Play with Bolt the robot
Five minutes with Bolt the robot. Vote, say why, then show the answer.
- 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. - 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. - When a program reaches if and else, it runs both paths. (Always · Sometimes · Never)
Answer: Never. It runs exactly one of them, and then carries on. - Which number makes this true: it's bigger than 5, smaller than 8, and even?
Answer: 6. 7 is odd, so only 6 fits. - 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.
Part 1 of 3 · learn, see, practise
if and else: two doors
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
password = input("Password? ")Put open in the Input box. Say: this is the question.
if password == "open":Two equals signs ask: are they the same? Point at the colon. Press Enter and see the indent.
print("Come in!")Four spaces in. This line only runs if it's true.
else:Back to the left. else also has a colon.
print("Go away!")Run it, then change the Input box to a wrong password.
▶ Output
(nothing is printed)
📦 Memory boxes
▶ Output
Age? 11 You can ride the big slide!
📦 Memory boxes
11intTry 9, 10 and 11 in the Input box. What does >= mean?
Practise it
Start with the warm-up and go as far as you can. The stretch questions are meant to be hard.
1.1 Ask for a colour. If it's blue, print Same!, otherwise print Different!
▶ Output
(nothing is printed)
📦 Memory boxes
Model answer (for the teacher)
c = input("Colour? ")
if c == "blue":
print("Same!")
else:
print("Different!")1.2 Fix the bug: the if line is missing something.
▶ Output
Line 2: SyntaxError: expected ':'
📦 Memory boxes
Model answer (for the teacher)
score = 10
if score == 10:
print("Perfect")1.3 Fix the two bugs: = should be ==, and the print is not moved in.
▶ Output
Line 2: SyntaxError: expected ':'
📦 Memory boxes
Model answer (for the teacher)
x = 5
if x == 5:
print("Five")1.4 Ask for a number. If it's bigger than 100, print Big. Otherwise print Small.
▶ Output
(nothing is printed)
📦 Memory boxes
Model answer (for the teacher)
n = int(input("Number? "))
if n > 100:
print("Big")
else:
print("Small")1.5 Odd or even? Ask for a number and print Even or Odd, using % 2.
▶ Output
(nothing is printed)
📦 Memory boxes
Model answer (for the teacher)
n = int(input("Number? "))
if n % 2 == 0:
print("Even")
else:
print("Odd")🎁 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