If Statements, online
Six activities your students do on their own devices. See who's finished, and their scores.
Learning
Understanding
Testing
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 > 3instead ofif 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.
PREVIOUS · MODULE 13Boolean Logic
YOU ARE HERE · MODULE 14If Statements
NEXT · MODULE 15elif Statements
What students will learn in this module
Every question in Module 14
Quick questions
- What does the if statement check?AWhether a condition is TrueBHow many times to loop
- What goes at the end of an if line?AA semicolon ;BA colon :
- How does Python know what's inside an if block?AIndentation (spaces)BCurly braces {}
- if 10 > 5:\n print('Yes')\nWhat prints?ANothingBYes
- if 3 > 7:\n print('Yes')\nWhat prints?ANothingBYes
Key terms
Students type the meaning of:
ifConditionColon :Indentation
Match the pairs
if x > 5
print('big')Match it to what it doesif x > 5:
print('big')Match it to what it doesif age >= 18:
print('Adult')Match it to what it doesif True:
print('yes')Match it to what it doesx = 10
if x > 5:
print('big')Match it to what it doesx = 3
if x > 5:
print('big')Match it to what it doesFill in the blanks
__ 5 > 3: print('Yes')if age >= 13_ print('Teen')if x == 10: _____('Match')if score __ 50: print('Pass')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')
