๐Ÿ Python for beginners ยท session 5 of 58 ยท 60 minutes ยท ๐ŸŽ free with an account

Making decisions: if, elif and else

Programs can choose. With if, elif and else a program checks something and does different things depending on the answer. Practise each kind of decision before building a grade machine, a bill calculator and a game judge.

๐ŸŽ Unlock free: make an account
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-up4 min
  2. True or False6 min
  3. if and else8 min
  4. elif8 min
  5. and, or, not7 min
  6. Grade machine7 min
  7. Electricity bill8 min
  8. Rock, paper, scissors7 min
  9. Quiz4 min
  10. Set the project1 min

By the end you can

  • Compare values with == != < > <= >=
  • Write if and else with correct indentation
  • Choose between many cases with elif
  • Combine conditions with and, or and not

Before you start

  • Session 3: input() and converting to numbers

Have ready

  • This page
  • Cards that say YES and NO (optional)

Beginner ยท ages 10 and up

Warm-up ยท think first

A ride says: "You must be at least 120 cm tall." Write the rule as a yes/no question the gate machine asks, and what it does for each answer.

Show the answer

Is height at least 120? Yes: open the gate. No: "Sorry, not yet". Every decision is a yes/no question with an action for each answer.

Teacher tip: Act it out with different heights; ask what happens at exactly 120.

More warm-ups for every class โ†’

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 Code

    Run this exact code: score = 7 if score == 10: print('Gold') elif score >= 5: print('Silver') else: print('Try again') Notice which word appears.

  2. ๐Ÿ”ง

    Level 2 ยท Tweak it

    Change Score Numbers

    In that same score code, change 7 to 3 and change >= 5 to >= 8. Predict Gold, Silver or Try again, then run it.

  3. ๐Ÿ› ๏ธ

    Level 3 ยท Build it

    Build Your Gate

    Make your own Python decision for a mini game. Set key = True and energy = 2. Use if, elif, else and one and/or/not to print Open, Wait or Locked. Test two changes.

Part 1 of 4 ยท learn, see, practise

Questions with True or False answers

A comparison gives True or False. == asks "equal?", != "not equal?", and < > <= >= compare sizes.

One = stores a value; two == ask a question.

Example: run it, then change it

โ–ถ Output

True
False
True
False

๐Ÿ“ฆ Memory boxes

height125int

Change height to 120 and predict the first two lines.

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 x = 15. Print whether x is greater than 10, then whether x equals 15.

Task 1.1

โ–ถ Output

(nothing is printed)

๐Ÿ“ฆ Memory boxes

x15int
๐Ÿง‘โ€๐Ÿซ Model answer (for the teacher)

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

The answer green = the 2 lines the student writes

x = 15print(x > 10)print(x == 15)

What it prints

True
True

What โœ“ Check looks for

  • it prints exactly:
    True
    True
  • With x = 5, it prints exactly:
    False
    False
Core

1.2 a = 7 and b = 7. Print whether they are equal, then whether they are different.

Task 1.2

โ–ถ Output

(nothing is printed)

๐Ÿ“ฆ Memory boxes

a7intb7int
๐Ÿง‘โ€๐Ÿซ Model answer (for the teacher)

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

The answer green = the 2 lines the student writes

a = 7b = 7print(a == b)print(a != b)

What it prints

True
False

What โœ“ Check looks for

  • it prints exactly:
    True
    False
  • With a = 3, it prints exactly:
    False
    True
Stretch ๐Ÿ”ฅ

1.3 n = 24. Print whether n is even, then whether n is a multiple of 3.

Task 1.3

โ–ถ Output

(nothing is printed)

๐Ÿ“ฆ Memory boxes

n24int
๐Ÿง‘โ€๐Ÿซ Model answer (for the teacher)

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

The answer green = the 2 lines the student writes

n = 24print(n % 2 == 0)print(n % 3 == 0)

What it prints

True
True

What โœ“ Check looks for

  • it prints exactly:
    True
    True
  • With n = 25, it prints exactly:
    False
    False
  • With n = 9, it prints exactly:
    False
    True

๐ŸŽ 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: if and else, with practice at three levels
  • Part 3: Many choices with elif, with practice at three levels
  • Part 4: and, or, not, with practice at three levels
  • Class activity 1: The grade machine
  • Class activity 2: Electricity bill
  • Class activity 3: Rock, paper, scissors judge
  • A 8-question quiz
  • After-class project: My quiz 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

Making decisions: if, elif and else: questions

What is the difference between if, elif and else in Python?

if checks first, elif checks more conditions when earlier ones were False, and else runs when none were True.

Why does Python use indentation?

It shows which lines belong to an if, elif or else.

What is == in Python?

It compares two values and gives True or False; one = stores a value.

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