Tuples – Operations

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

Tuples – Operations

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. What is an enumeration?
A A set of named constants
B A type of list
2. Why use enums instead of strings?
A Prevents typos and invalid values
B They're faster
3. Color.RED.value returns?
A The value assigned to RED (e.g., 1)
B The string 'RED'
4. Color.RED.name returns?
A 1
B 'RED' (the name as a string)
5. Can enum members be compared?
A No
B Yes Color.RED == Color.RED is True

Match the Pairs

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

Left columnRight column
1from Enum import enum AOk: Access the numeric value of an enum member
2Color(RED) BValid: Correct import for Enum class
3from enum import Enum COutput: <class 'bool'>
4Color.RED.value DOutput: [0, 1, 2]
5list(range(3)) EError: Incorrect import — use from enum import Enum
6type(True) FError: Access members with Color.RED

Definitions

Enum

Fill in the Blanks

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

1.
from enum import ____ class Color(Enum): RED = 1
2.
class Color(____): RED = 1
3.
print(Color.RED._____)
4.
print(Color.RED.____)
5.
for c in _____: print(c)

Spot the Error

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

Question 1
A class Color(Enum):
B RED = 1
Question 2
A from enum import Enum
B
C class Color(Enum):
D RED = 1
E GREEN = 1
Question 3
A from enum import Enum
B
C class Color(Enum):
D RED = 1
E
F Color.RED = 2
Question 4
A from enum import Enum
B
C class Color(Enum):
D red = 1
Question 5
A from enum import Enum
B
C class Color(Enum):
D RED = 1
E
F if color == 'RED':

Answer Key

Tuples – Operations
Section A: Quick Questions
Q1
A — A set of named constants
Q2
A — Prevents typos and invalid values
Q3
A — The value assigned to RED (e.g., 1)
Q4
B — 'RED' (the name as a string)
Q5
B — Yes Color.RED == Color.RED is True
Section B: Match the Pairs
Q1
from Enum import enum → Error: Incorrect import — use from enum import Enum
Q2
Color(RED) → Error: Access members with Color.RED
Q3
from enum import Enum → Valid: Correct import for Enum class
Q4
Color.RED.value → Ok: Access the numeric value of an enum member
Q5
list(range(3)) → Output: [0, 1, 2]
Q6
type(True) → Output: <class 'bool'>
Section C: Definitions
Q1
Enum — A class for creating sets of named constants.~~Member
Section D: Fill in the Blanks
Q1
from enum import Enum class Color(Enum): RED = 1
Q2
class Color(Enum): RED = 1
Q3
print(Color.RED.value)
Q4
print(Color.RED.name)
Q5
for c in Color: print(c)
Section E: Spot the Error
Q1
A — Must import Enum first: from enum import Enum
Q2
E — Duplicate values create aliases, not new members. Use unique values.
Q3
F — Cannot reassign enum members they are immutable
Q4
D — Convention: enum member names should be UPPER_CASE
Q5
F — Compare with Color.RED, not the string 'RED'