AlgoMaster Logo

Tuples - Quiz

Last Updated: January 3, 2026

Tuples Exercises

29 quizzes

1
Code Completion

Complete the code to create an immutable ordered collection storing three status codes.

python
1
status_codes = (200, 404, 500)

Click an option to fill the blank:

2
Code Completion

Complete the code to get the third element from the tuple measurements.

python
1
third_value = measurements[]

Click an option to fill the blank:

3
Code Completion

Complete the code to concatenate two tuples of coordinates into a single tuple.

python
1
all_points = first_points second_points

Click an option to fill the blank:

4
Multiple Choice

Which statement about Python tuples is TRUE?

5
Multiple Choice

Which of the following creates a tuple with a single element 10?

6
Multiple Choice

Why can tuples be used as dictionary keys while lists cannot?

7
Multiple Choice

What is the result of this tuple operation? config = ("dev",) * 3

8
Multiple Choice

Given data = (10, 20, 30, 40), what does data[-2] return?

9
Multiple Choice

Which slicing expression returns the middle two elements of values = (1, 2, 3, 4)?

10
Multiple Choice

What happens in this unpacking? name, age = ("Alice", 30, "Engineer")

11
Multiple Choice

Given point = (3, 4), which unpacking is valid?

12
Multiple Choice

How do you access the field y from a named tuple Point defined as Point = namedtuple('Point', ['x', 'y'])?

13
Multiple Choice

Which import is correct for creating a named tuple?

14
Multiple Choice

Given Device = namedtuple('Device', ['name', 'ip']); d = Device('router', '10.0.0.1'), which is TRUE?

15
Sequencing

Order the steps to create a named tuple for a 2D point and use it to store coordinates.

Drag and drop to reorder, or use the arrows.

16
Sequencing

Order the steps to unpack a configuration tuple into separate variables and use one of them.

Drag and drop to reorder, or use the arrows.

17
Output Prediction

What is the output of this code?

1settings = ("dark", "english", "metric")
2print(settings[0] + "-" + settings[-1])
18
Output Prediction

What is the output of this code?

1data = (1, 2) * 2 + (3,)
2print(len(data))
19
Output Prediction

What is the output of this code?

1record = ("Alice", 30, "Engineer")
2name, _, role = record
3print(role)
20
Output Prediction

What is the output of this code?

1from collections import namedtuple
2User = namedtuple('User', ['username', 'active'])
3u = User('bob', True)
4print(u.username, u.active)
21
Output Prediction

What is the output of this code?

1values = (10, 20, 30, 40)
2start, *middle, end = values
3print(middle)
22
Bug Spotting

Find the bug in this tuple unpacking code used to handle API responses.

Click on the line(s) that contain the bug.

python
1
response = (200, 'OK')
2
status_code, message, payload = response
3
print(status_code, message)
23
Bug Spotting

Find the bug in this code that uses a named tuple to represent a point.

Click on the line(s) that contain the bug.

python
1
from collections import namedtuple
2
Point = namedtuple('Point', ['x', 'y'])
3
pt = Point(1, 2)
4
pt.x = 10
5
print(pt)
24
Matching

Match each tuple-related concept with the correct description.

Click an item on the left, then click its match on the right. Click a matched item to unmatch.

25
Matching

Match the tuple or named tuple usage with an appropriate example.

Click an item on the left, then click its match on the right. Click a matched item to unmatch.

26
Fill in the Blanks

Complete the code to safely create a dictionary using coordinate tuples as keys.

python
1
sensor_readings = {}
2
position =
3
sensor_readings[position] = 42.5
4
print(sensor_readings[])

Click an option to fill blank 1:

27
Fill in the Blanks

Complete the code to unpack a status tuple and log only the status text.

python
1
status = (200, 'OK', 'Success')
2
code, , details = status
3
print()

Click an option to fill blank 1:

28
Hotspot Selection

Click the line that attempts to modify an immutable tuple of coordinates.

Click on the line to select.

python
1
coords = (5, 10)
2
coords_list = list(coords)
3
coords_list[0] = 20
4
coords[0] = 20
5
print(coords)
29
Hotspot Selection

Click the line that incorrectly constructs a named tuple instance.

Click on the line to select.

python
1
from collections import namedtuple
2
Point = namedtuple('Point', ['x', 'y'])
3
pt1 = Point(1, 2)
4
pt2 = Point(x=3)
5
print(pt1, pt2)