bhylu.com

Advertisements

Tuple Exercises

Unpack a workshop record into descriptive names, then make a replacement tuple with a changed seat count.

Understand the idea

Write your own solution before opening the worked answer. Predict the output from the supplied values, then compare the actual result. Check both an ordinary case and the boundary described below; a passing example is more useful when you can explain why it passes.

Where to try it

Open this example with Try in playground. The code loads as editable text and does not run until you select Run. The first run downloads Python. Each run starts fresh; temporary files created by a script are not files on your PC.

Your task

Unpack a workshop record into descriptive names, then make a replacement tuple with a changed seat count.

Show the worked solution
Python

record = ("Python", 12)
title, seats = record
updated = (title, seats + 2)
print(record, updated)

Check the result

The original remains ('Python', 12), and the replacement has 14 seats.

Test one more case

Keep an alias to the original and confirm that creating a replacement does not change it.