elif Statements, online

Six activities your students do on their own devices. See who's finished, and their scores.

elif Statements in one minute

What students need to know

elif is checked only if the previous if was False. elif can use any comparison operator including ==.

elif is short for 'else if' — it adds another condition to check. x > 10 is False, so Python checks elif — 5 > 3 is True, so 'Medium' prints.

Mistakes students make

  • Python uses elif, not 'else if' (no space).
  • elif cannot appear without an if statement before it.
  • Missing colon at the end of the elif line.
  • elif must be lowercase — Elif is not valid Python.
PREVIOUS · MODULE 14If Statements
YOU ARE HERE · MODULE 15elif Statements
NEXT · MODULE 16else Statements

Discover other journeys with this module

What students will learn in this module

Every question in Module 15

Quick questions

  1. What does elif stand for?Aelse in functionBelse if
  2. When does an elif block run?AWhen the if above is False and elif is TrueBAlways
  3. x = 5\nif x > 10:\n print('Big')\nelif x > 3:\n print('Medium')\nWhat prints?AMediumBBig
  4. Can you have multiple elif blocks?ANoBYes
  5. Can elif appear before if?ANo if must come firstBYes

Key terms

Students type the meaning of:

  • elif
  • Chaining
  • First match wins
  • Condition order

Match the pairs

else if x > 5:
    print('mid')
Match it to what it does
elif x > 5
    print('mid')
Match it to what it does
if x > 10:
    print('big')
elif x > 5:
    print('mid')
Match it to what it does
elif score == 100:
    print('perfect')
Match it to what it does
x = 7
if x > 10:
    print('big')
elif x > 5:
    print('mid')
Match it to what it does
x = 15
if x > 10:
    print('big')
elif x > 5:
    print('mid')
Match it to what it does

Fill in the blanks

  1. if x > 10:
        print('Big')
    ____ x > 5:
        print('Medium')
  2. if score >= 90:
        print('A')
    elif score >= 80_
        print('B')
  3. if age >= 18:
        print('Adult')
    ____ age >= 13:
        print('Teen')
  4. if temp >= 35:
        print('Hot')
    elif temp __ 25:
        print('Warm')
  5. if day == 'Monday':
        print('Start')
    elif day __ 'Saturday':
        print('Weekend')

Spot the error

Question 1

Aif x > 10:B    print('Big')Celse if x > 5:D    print('Medium')

Question 2

Ax = 7Belif x > 5:C    print('Medium')

Question 3

Aif x > 10:B    print('Big')Celif x > 5D    print('Medium')

Question 4

Aif x > 10:B    print('Big')CElif x > 5:D    print('Medium')

Question 5

Aif x > 10:B    print('Big')Celif x > 5:Dprint('Medium')