← IGCSE Computer Science Paper 2

CASE as if/elif/else in Python

Python has no CASE, so write it as an if/elif chain testing the same variable. The first value uses if, each other value uses elif, and OTHERWISE becomes else.

Understanding CASE as if/elif/else in Python in IGCSE Computer Science Paper 2

What it does: The first CASE value starts the chain with if, and Python uses == to compare Move with the value. A CASE statement checks one variable, so each extra value is an elif comparing that same variable. A comparison in Python uses ==. A single = is assignment and causes a syntax error here. OTHERWISE becomes else:. Python has no otherwise keyword. else has no condition after it. It is just else: and it catches every value not matched above.

Common mistakes: A single = assigns a value. To test whether move equals "L" you need the comparison operator ==, so the line should be if move == "L":. Every if line in Python must end with a colon. The line should be if move == "F":.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 188–213) and word search (Modules 188–231) and definitions worksheet (Modules 188–213) and word scramble (Modules 188–213).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
Python has no CASE statement. How do you write CASE OF Move in Python?
A CASE OF ... ENDCASE block, exactly as in pseudocodeAn if/elif/else chain that tests Move each time
Matches
if Move == "F": print("Forward") if Move == "B": print("Back")
↓
The second value uses if instead of elif, so it is a separate test and not part of the same chain. It should be elif Move == "B":
Applying
Meanings
Term
if/elif/else
Meaning
Python has no CASE, so write it as an if/elif chain testing the same variable. The first value uses if, each other value uses elif, and OTHERWISE becomes else.
Practice
Move = "L"
Testing
Gaps
move == "L":
Check Answer
Spots
1move = input("Move: ")
2if move = "L":

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Armadillo' badge — Shield Bearer, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

▶ Run these on the board — two answers, the class points left or right, you reveal why. No devices.

1. Python has no CASE statement. How do you write CASE OF Move in Python?
A. An if/elif/else chain that tests Move each time ✓
B. A CASE OF ... ENDCASE block, exactly as in pseudocode
Python has no CASE keyword, so we use an if/elif/else chain that tests the same variable, Move.
2. Which keyword does the FIRST value of a CASE OF Move become in Python?
A. elif Move == "L":
B. if Move == "L": ✓
The first value starts the chain, so it uses if. Every later value uses elif.
3. Which line is the correct Python for the second value in a CASE OF Move?
A. elif Move == "R": ✓
B. elif Move = "R":
A comparison in Python uses ==. A single = is assignment and causes a syntax error here.
4. The pseudocode has OTHERWISE OUTPUT "Invalid". How is this written in Python?
A. otherwise:
B. else: ✓
OTHERWISE becomes else:. Python has no otherwise keyword.
5. Which is the correct way to write the end of a CASE OF Move as Python?
A. else: followed by an indented print("Invalid") ✓
B. else Move: followed by an indented print("Invalid")
else has no condition after it. It is just else: and it catches every value not matched above.

Match the Pairs

elif Move == "B": → Tests the next CASE value after the first, like the line B: in a CASE OF Move statement
else: → Runs when none of the if or elif tests match, just like OTHERWISE in a CASE statement
The first value in CASE OF Move becomes an if that tests the variable Move → if Move == "F":
Every value in the chain tests the same variable, so each elif compares Move again → elif Move == "L":
if Move == "F": print("Forward") if Move == "B": print("Back") → The second value uses if instead of elif, so it is a separate test and not part of the same chain. It should be elif Move == "B":
elif Move == "B": print("Back") OTHERWISE: print("Invalid") → OTHERWISE does not exist in Python. The catch-all branch must be written as else:

Key Term

if/elif/else
Python has no CASE, so write it as an if/elif chain testing the same variable. The first value uses if, each other value uses elif, and OTHERWISE becomes else.

Fill in the Blanks

1. if move == "L": print("Left") elif move == "R":
Hint: Type the keyword that starts the chain for the first CASE value.
2. if move == "L": print("Left") elif move == "R":
Hint: Type the keyword used for each further value after the first one.
3. elif move == "R": print("Right") else:
Hint: Type the keyword that replaces OTHERWISE and catches every other value.
4. if move == "L": print("Left") elif move == "R":
Hint: Type the operator that checks whether the variable equals a value.
5. if move == "L": print("Left") elif move == "R":
Hint: Type the variable that every branch in the chain tests, as in CASE OF.

Spot the Error

Question 1
A move = input("Move: ")
B if move = "L":
C print("Left")
D elif move == "R":
E print("Right")
Line B — A single = assigns a value. To test whether move equals "L" you need the comparison operator ==, so the line should be if move == "L":.
Question 2
A move = input("Move: ")
B if move == "F"
C print("Forward")
D else:
E print("Invalid")
Line B — Every if line in Python must end with a colon. The line should be if move == "F":.
Question 3
A move = input("Move: ")
B elif move == "U":
C y = y + 1
D elif move == "D":
E y = y - 1
Line B — The first value of the CASE must use if, not elif. An elif cannot start a chain because there is no if before it. It should be if move == "U":.
Question 4
A move = input("Move: ")
B if move == "U":
C print("Up")
D otherwise:
E print("Unknown move")
Line D — Python has no OTHERWISE keyword. OTHERWISE in a CASE statement becomes else: in Python.
Question 5
A if move == "L":
B x = x - 1
C else if move == "R":
D x = x + 1
Line C — Python does not use else if. Each extra value in the CASE is written as elif, so the line should be elif move == "R":.

Student with a class code? Join your class →

Classroom tools: Hangman · Bingo · Heads or Tails · Higher or Lower · Name Picker · Team Generator · Seating Plan