If Statements, online

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

If Statements in one minute

What students need to know

An if statement runs a block of code only when its condition evaluates to True. The condition is any expression that resolves to True or False (like 5 > 3), the line must end with a colon, and the code that should run sits on the next line, indented underneath — usually by 4 spaces. That indentation isn't a style choice: it's how Python knows which lines belong inside the if block.

Mistakes students make

  • Forgetting the trailing colon (if 5 > 3 instead of if 5 > 3:) is the single most common error.
  • Inconsistent indentation is the other — mixing tabs and spaces, or indenting by a different amount than the rest of the block, raises an IndentationError.

Discover other journeys with this module

What students will learn in this module

Every question in Module 14

Quick questions

  1. What does the if statement check?AWhether a condition is TrueBHow many times to loop
  2. What goes at the end of an if line?AA semicolon ;BA colon :
  3. How does Python know what's inside an if block?AIndentation (spaces)BCurly braces {}
  4. if 10 > 5:\n print('Yes')\nWhat prints?ANothingBYes
  5. if 3 > 7:\n print('Yes')\nWhat prints?ANothingBYes

Key terms

Students type the meaning of:

  • if
  • Condition
  • Colon :
  • Indentation

Match the pairs

if x > 5
    print('big')
Match it to what it does
if x > 5:
print('big')
Match it to what it does
if age >= 18:
    print('Adult')
Match it to what it does
if True:
    print('yes')
Match it to what it does
x = 10
if x > 5:
    print('big')
Match it to what it does
x = 3
if x > 5:
    print('big')
Match it to what it does

Fill in the blanks

  1. __ 5 > 3:
        print('Yes')
  2. if age >= 13_
        print('Teen')
  3. if x == 10:
        _____('Match')
  4. if score __ 50:
        print('Pass')
  5. if name __ 'Alice':
        print('Hi')

Spot the error

Question 1

Aif 5 > 3:
    print('Yes')Bif 5 > 3
    print('Yes')Cif 10 > 8:
    print('Big')Dif x > 0:
    print('Positive')

Question 2

Aif 5 > 3:
print('Yes')Bif x > 0:
    print('Positive')Cif done:
    print('Done')Dif ok:
    print('OK')

Question 3

Aif 5 > 3:
    print('Yes')Bif ready:
    print('Go')CIf 10 > 5:
    print('Big')Dif name:
    print('Hi')

Question 4

Aif done:
    print('Done')
    print('OK')Bif ok:
    print('A')
    print('B')Cif ready:
    print('Go')
    print('Start')Dif 5 > 3:
    print('Yes')
     print('Done')

Question 5

Aif score == 10:
    print('Match')Bif x = 5:
    print('Five')Cif age == 18:
    print('Adult')Dif n == 0:
    print('Zero')