else Statements

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

else Statements

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. When does else run?
A Always
B When all if/elif conditions are False
2. Does else have a condition?
A Yes
B No it catches everything left
3. x = 2\nif x > 10:\n print('Big')\nelse:\n print('Small')\nWhat prints?
A Small
B Big
4. Where must else appear?
A After the last if or elif
B Before if
5. Can you have else without if?
A No
B Yes

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1else x > 5: print('no') AValid: else as fallback
2else: print('no') elif x > 2: print('mid') BOutput: small
3if x > 0: print('pos') else: print('neg') CError: elif can't come after else
4else: print('other') DOutput: big
5x = 2 if x > 5: print('big') else: print('small') EError: else has no condition
6x = 8 if x > 5: print('big') else: print('small') FOk: else with colon only

Definitions

else

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
if x > 10: print('Big') ____: print('Small')
2.
if age >= 18: print('Adult') else_ print('Minor')
3.
if score >= 50: print('Pass') ____: print('Fail')
4.
if name == 'Alice': print('Hi') ____: print('Unknown')
5.
if temp >= 30: _____('Hot') else: print('Cold')

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A if x > 10:
B print('Big')
C else x <= 10:
D print('Small')
Question 2
A if x > 10:
B print('Big')
C else
D print('Small')
Question 3
A else:
B print('Small')
Question 4
A if x > 10:
B print('Big')
C Else:
D print('Small')
Question 5
A if x > 10:
B print('Big')
C else:
D print('Small')

Answer Key

else Statements
Section A: Quick Questions
Q1
B — When all if/elif conditions are False
Q2
B — No it catches everything left
Q3
A — Small
Q4
A — After the last if or elif
Q5
A — No
Section B: Match the Pairs
Q1
else x > 5: print('no') → Error: else has no condition
Q2
else: print('no') elif x > 2: print('mid') → Error: elif can't come after else
Q3
if x > 0: print('pos') else: print('neg') → Valid: else as fallback
Q4
else: print('other') → Ok: else with colon only
Q5
x = 2 if x > 5: print('big') else: print('small') → Output: small
Q6
x = 8 if x > 5: print('big') else: print('small') → Output: big
Section C: Definitions
Q1
else — Catch-all block that runs when all if/elif conditions are False. else never has a condition - just else: with a colon.~~if/else
Section D: Fill in the Blanks
Q1
if x > 10: print('Big') else: print('Small')
Q2
if age >= 18: print('Adult') else: print('Minor')
Q3
if score >= 50: print('Pass') else: print('Fail')
Q4
if name == 'Alice': print('Hi') else: print('Unknown')
Q5
if temp >= 30: print('Hot') else: print('Cold')
Section E: Spot the Error
Q1
C — else does not take a condition just else: with no expression
Q2
C — Missing colon after else
Q3
A — else cannot stand alone it must follow an if or elif
Q4
C — else must be lowercase Else is not valid Python
Q5
D — The print inside else must be indented