Enumerations – Basics

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

Enumerations – Basics

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. What is a tuple?
A An immutable ordered sequence
B A mutable list
2. How do you create a tuple?
A Parentheses () or commas
B Square brackets []
3. Can you change a tuple's items?
A Yes
B No tuples are immutable
4. t = (1, 2, 3)\nt[0] returns?
A 1
B (1)
5. How do you create a single-item tuple?
A (1)
B (1,) with a trailing comma

Match the Pairs

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

Left columnRight column
1t = (1) AValid: Tuple with three items
2t[0] = 5 BOk: Unpack a tuple into two variables
3t = (1, 2, 3) COutput: 4
4a, b = (10, 20) DError: Single item needs trailing comma: (1,)
5(1, 2, 3)[1] EError: Tuples are immutable — cannot assign
6len((4, 5, 6, 7)) FOutput: 2

Definitions

Tuple

Fill in the Blanks

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

1.
point = (3, 4) print(point[_])
2.
single = (42_) # single-item tuple
3.
a, b = (10, 20) print(_)
4.
t = (1, 2, 3) print(___(t))
5.
print(2 __ (1, 2, 3))

Spot the Error

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

Question 1
A t = (1, 2, 3)
B t[0] = 99
C print('Updated:', t)
D print('Done')
Question 2
A t = (1, 2, 3)
B t.append(4)
C print('Tuple:', t)
D print('Done')
Question 3
A single = (42)
B print('Type:', type(single))
C print('Value:', single)
D # expects tuple
Question 4
A coords = (1, 2, 3)
B a, b = coords
C print('a:', a, 'b:', b)
D print('Done')
Question 5
A t = (1, 2, 3)
B first = t(0)
C print('First:', first)
D print('Done')

Answer Key

Enumerations – Basics
Section A: Quick Questions
Q1
A — An immutable ordered sequence
Q2
A — Parentheses () or commas
Q3
B — No tuples are immutable
Q4
A — 1
Q5
B — (1,) with a trailing comma
Section B: Match the Pairs
Q1
t = (1) → Error: Single item needs trailing comma: (1,)
Q2
t[0] = 5 → Error: Tuples are immutable — cannot assign
Q3
t = (1, 2, 3) → Valid: Tuple with three items
Q4
a, b = (10, 20) → Ok: Unpack a tuple into two variables
Q5
(1, 2, 3)[1] → Output: 2
Q6
len((4, 5, 6, 7)) → Output: 4
Section C: Definitions
Q1
Tuple — An immutable ordered sequence created with parentheses.~~Immutable
Section D: Fill in the Blanks
Q1
point = (3, 4) print(point[0])
Q2
single = (42,) # single-item tuple
Q3
a, b = (10, 20) print(b)
Q4
t = (1, 2, 3) print(len(t))
Q5
print(2 in (1, 2, 3))
Section E: Spot the Error
Q1
B — Tuples are immutable: can't change items. Create a new tuple instead.
Q2
B — Tuples don't have append(): they're immutable
Q3
A — (42) is just the number 42. Need trailing comma: (42,) for a tuple.
Q4
B — 3 values but only 2 variables: need matching count for unpacking
Q5
B — Use square brackets for indexing: t[0] not t(0)