elif Statements

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

elif Statements

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. What does elif stand for?
A else in function
B else if
2. When does an elif block run?
A When the if above is False and elif is True
B Always
3. x = 5\nif x > 10:\n print('Big')\nelif x > 3:\n print('Medium')\nWhat prints?
A Medium
B Big
4. Can you have multiple elif blocks?
A No
B Yes
5. Can elif appear before if?
A No if must come first
B Yes

Match the Pairs

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

Left columnRight column
1else if x > 5: print('mid') AOutput: mid
2elif x > 5 print('mid') BError: Use elif not 'else if'
3if x > 10: print('big') elif x > 5: print('mid') COk: elif with == comparison
4elif score == 100: print('perfect') DOutput: big
5x = 7 if x > 10: print('big') elif x > 5: print('mid') EValid: elif checks next condition
6x = 15 if x > 10: print('big') elif x > 5: print('mid') FError: Missing colon after elif

Definitions

elif

Fill in the Blanks

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

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

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

Question 1
A if x > 10:
B print('Big')
C else if x > 5:
D print('Medium')
Question 2
A x = 7
B elif x > 5:
C print('Medium')
Question 3
A if x > 10:
B print('Big')
C elif x > 5
D print('Medium')
Question 4
A if x > 10:
B print('Big')
C Elif x > 5:
D print('Medium')
Question 5
A if x > 10:
B print('Big')
C elif x > 5:
D print('Medium')

Answer Key

elif Statements
Section A: Quick Questions
Q1
B — else if
Q2
A — When the if above is False and elif is True
Q3
A — Medium
Q4
B — Yes
Q5
A — No if must come first
Section B: Match the Pairs
Q1
else if x > 5: print('mid') → Error: Use elif not 'else if'
Q2
elif x > 5 print('mid') → Error: Missing colon after elif
Q3
if x > 10: print('big') elif x > 5: print('mid') → Valid: elif checks next condition
Q4
elif score == 100: print('perfect') → Ok: elif with == comparison
Q5
x = 7 if x > 10: print('big') elif x > 5: print('mid') → Output: mid
Q6
x = 15 if x > 10: print('big') elif x > 5: print('mid') → Output: big
Section C: Definitions
Q1
elif — Short for 'else if' - checks another condition if the previous was False.~~Chaining
Section D: Fill in the Blanks
Q1
if x > 10: print('Big') elif x > 5: print('Medium')
Q2
if score >= 90: print('A') elif score >= 80: print('B')
Q3
if age >= 18: print('Adult') elif age >= 13: print('Teen')
Q4
if temp >= 35: print('Hot') elif temp >= 25: print('Warm')
Q5
if day == 'Monday': print('Start') elif day == 'Saturday': print('Weekend')
Section E: Spot the Error
Q1
C — Python uses elif, not 'else if' (no space)
Q2
B — elif cannot appear without an if statement before it
Q3
C — Missing colon at the end of the elif line
Q4
C — elif must be lowercase — Elif is not valid Python
Q5
D — The print inside elif must be indented