Tuples – Practical Use

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

Tuples – Practical Use

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Why use Color.RED instead of 'red'?
A It's shorter
B Typos cause errors immediately
2. Can enums be used in if/elif chains?
A No
B Yes great for state machines
3. What does auto() do?
A Automatically assigns incrementing values
B Creates the class
4. Can enums be dictionary keys?
A Yes they are hashable
B No
5. When should you use enums?
A For a fixed set of choices (like status, direction, color)
B For all variables

Match the Pairs

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

Left columnRight column
1if status = Status.ACTIVE: AError: Use for item in Status: to iterate
2for item in Status.members: BError: Use == not = for comparison
3if status == Status.ACTIVE: CValid: Compare enum members with ==
4for item in Status: DOutput: 1
5min(3, 1, 4, 1, 5) EOutput: 5
6max(3, 1, 4, 1, 5) FOk: Iterate through all enum members

Definitions

Tuples

Fill in the Blanks

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

1.
from enum import Enum, ____ class Color(Enum): RED = auto()
2.
prices = {Size.SMALL: 5} print(prices[Size._____])
3.
if status __ Status.ACTIVE: print('Active')
4.
for item in _____: print(item.name)
5.
class Size(Enum): SMALL = ____()

Spot the Error

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

Question 1
A from enum import Enum
B class Status(Enum):
C ACTIVE = 1
D INACTIVE = 2
E if status == 'active':
Question 2
A prices = {'SMALL': 5, 'MEDIUM': 8}
B size = 'SMALL'
C cost = prices['SMAL']
D print('Cost:', cost)
Question 3
A from enum import Enum, auto
B
C class Color(Enum):
D RED = auto
E GREEN = auto
Question 4
A def paint(color):
B if color == 'red':
C pass
D
E paint('rad')
Question 5
A from enum import Enum
B class Color(Enum):
C RED = 1
D
E if color == Color.RED.value:

Answer Key

Tuples – Practical Use
Section A: Quick Questions
Q1
B — Typos cause errors immediately
Q2
B — Yes great for state machines
Q3
A — Automatically assigns incrementing values
Q4
A — Yes they are hashable
Q5
A — For a fixed set of choices (like status, direction, color)
Section B: Match the Pairs
Q1
if status = Status.ACTIVE: → Error: Use == not = for comparison
Q2
for item in Status.members: → Error: Use for item in Status: to iterate
Q3
if status == Status.ACTIVE: → Valid: Compare enum members with ==
Q4
for item in Status: → Ok: Iterate through all enum members
Q5
min(3, 1, 4, 1, 5) → Output: 1
Q6
max(3, 1, 4, 1, 5) → Output: 5
Section C: Definitions
Q1
Tuples — A tuple is an ordered, fixed-size collection of values. Conceptually, it acts like a single record or row (e.g., a person's name and age), where each specific position holds a distinct piece of related data.
Section D: Fill in the Blanks
Q1
from enum import Enum, auto class Color(Enum): RED = auto()
Q2
prices = {Size.SMALL: 5} print(prices[Size.SMALL])
Q3
if status == Status.ACTIVE: print('Active')
Q4
for item in Color: print(item.name)
Q5
class Size(Enum): SMALL = auto()
Section E: Spot the Error
Q1
E — Compare with enum member, not string: prevents typos
Q2
C — String key typo passes silently. Enum key would cause clear error.
Q3
D — auto needs parentheses: auto() not just auto
Q4
E — String 'rad' passes silently. Enum Color.RED would error immediately.
Q5
E — Compare with the member (Color.RED), not its value: loses type safety