Python ยท Python Collections

Tuples: Practice Questions

100 questions. Try each one yourself before checking the answer.

Short on time? Filter by Must Do for the 25 questions that cover this topic on their own.

Q1Creating TuplesEasyMust Do

Create a tuple called point holding 10 and 20, then print it and its type.

Q2Creating TuplesEasy

Create a tuple holding an int, a float, a string and a bool, then print it. Like a list, one tuple can mix types.

Q3Creating TuplesEasy

Create an empty tuple and print it with its length, then create a tuple from the list [1, 2, 3] using tuple().

Q4IndexingEasyMust Do

Using colours = ("red", "green", "blue"), print the first item and the last item.

Q5IndexingEasy

Using scores = (88, 92, 79, 95, 60), print how many items it holds and the value in the middle.

Q6SlicingEasyMust Do

Using numbers = (10, 20, 30, 40, 50), print the first three items and the last two using slices. Note that slicing a tuple gives back another tuple.

Q7SlicingEasy

Using the same tuple, print it reversed with a slice, and print every second item.

Q8MembershipEasy

Using days = ("Mon", "Tue", "Wed"), print whether "Tue" is in it and whether "Sun" is not in it.

Q9ImmutabilityEasyMust Do

Show that a tuple cannot be edited: write the line that would fail as a comment, explain the error, then produce a changed version by building a new tuple.

Q10ImmutabilityEasy

Show that a tuple has no .append(), .remove() or .sort(), and explain in a comment why that is the whole point of the type.

Q11Single-Element TuplesEasyMust Do

Create a tuple holding only the number 5. Print its type, then print the type of (5) and explain the difference in a comment.

Q12PackingEasyMust Do

Create a tuple without using brackets at all, by writing record = "Asha", 22, "Pune". Print it and its type.

Q13UnpackingEasyMust Do

Given record = ("Asha", 22, "Pune"), unpack it into three variables name, age and city on one line, then print each.

Q14UnpackingEasy

Swap two variables using tuple packing and unpacking, and explain in a comment what Python actually does with the right-hand side.

Q15UnpackingEasy

Show what happens when the number of variables does not match the number of items, and explain the error in a comment.

Q16Tuple MethodsEasy

Using votes = ("yes", "no", "yes", "yes", "no"), print how many "yes" votes there are and the position of the first "no".

Q17LoopingEasy

Using colours = ("red", "green", "blue"), print each colour on its own line with a for loop.

Q18LoopingEasy

Using the same tuple, print each colour with its position, like 1. red.

Q19ConcatenationEasy

Given a = (1, 2) and b = (3, 4), join them with + and repeat a three times with *. Print both results and show a is unchanged.

Q20Nested TuplesEasy

Create person = ("Asha", (12, 5, 2001)) where the second item is a date. Print the whole tuple, just the date, and just the year.

Q21ConversionEasy

Convert the list ["a", "b", "c"] into a tuple, then convert it back into a list. Print the type at each step.

Q22ConversionEasy

Turn the word "python" into a tuple of its characters, then print the tuple and its length.

Q23ComparisonEasy

Print whether (1, 2, 3) equals (1, 2, 3), and whether it equals [1, 2, 3]. Explain the second result.

Q24AggregationEasy

Using marks = (78, 92, 65, 88, 71), print the total, highest, lowest and average. All the list aggregation functions work on tuples too.

Q25Tuple vs ListEasyMust Do

Create the same three values as both a list and a tuple. Add an item to the list, show the tuple cannot do the same, and print both.

Q26Functions & TuplesMediumMust Do

Write min_max(numbers) that returns both the smallest and largest value. Unpack the result into two variables, then explain in a comment what the function actually handed back.

Q27Functions & TuplesMedium

Call the same min_max() but store the result in one variable instead of unpacking it. Print the variable, its type, and each item by index.

Q28Functions & TuplesMedium

Write stats(numbers) returning the count, total and average as a tuple. Print the result both unpacked and as a whole.

Q29Functions & TuplesMedium

Write describe(point) that takes a (x, y) tuple and prints a sentence, unpacking the parameter inside the function body.

Q30Star UnpackingMediumMust Do

Given numbers = (1, 2, 3, 4, 5), unpack the first value into first and everything else into rest using a star. Print both and the type of rest.

Q31Star UnpackingMedium

Using the same tuple, unpack everything except the last item into start, and the last into last.

Q32Star UnpackingMedium

Given scores = (10, 20, 30, 40, 50), capture the first, the last, and everything between them in one statement.

Q33UnpackingMedium

Given person = ("Asha", (12, 5, 2001)), unpack the name and the three date parts in a single statement using nested brackets.

Q34List of TuplesMedium

Build a list of (name, mark) tuples for three students by appending in a loop over two given lists, then print the list.

Q35List of TuplesMediumMust Do

Loop over records = [("Asha", 88), ("Raj", 74), ("Meera", 91)], unpacking each tuple in the for statement itself, and print an aligned line per student.

Q36List of TuplesMedium

Using the same records, split them back into two separate lists of names and marks.

Q37SortingMediumMust Do

Sort records = [("Raj", 74), ("Asha", 88), ("Meera", 91)] with plain sorted() and explain in a comment which field decided the order.

Q38SortingMedium

Sort scores = [(88, "Asha"), (74, "Raj"), (88, "Bala"), (91, "Meera")] and explain how the tie between the two 88s is broken.

Q39SortingMedium

Given records = [("Asha", 88), ("Raj", 74), ("Meera", 91)], sort them by mark by rebuilding each tuple with the mark first, sorting, then printing the name first again.

Q40SortingMedium

Sort a tuple of numbers. Show that sorted() works on it but hands back a list, then convert the result back to a tuple.

Q41ImmutabilityMedium

"Change" the tuple (10, 20, 30) so the middle value becomes 99, by converting to a list, editing, and converting back. Print the old and new tuples.

Q42ComparisonMediumMust Do

Print the result of comparing (1, 2, 3) with (1, 2, 4), (1, 3) and (1, 2). Explain the rule in a comment.

Q43List of TuplesMedium

Given a list of (item, price) tuples, find and print the most expensive item's name and price.

Q44Nested TuplesMediumMust Do

Store a 3x3 grid as a tuple of tuples, print it row by row, and print the total of every number.

Q45Tuple vs ListMedium

Store a fixed configuration as a tuple of constants and use it. Explain in a comment why a tuple is the better choice than a list here.

Q46Star UnpackingMedium

Write a function that takes a full name as a single string and returns first name, middle names and last name as a tuple, coping with any number of middle names.

Q47RecordsMedium

Given a list of (name, mark) records, build two new lists โ€” one of records that passed (40 or more) and one that failed โ€” then print both counts.

Q48SearchingMedium

Given a list of (code, city) tuples, ask the user for a code and print the matching city, or a not-found message.

Q49RecordsMedium

Given a list of (item, quantity, price) tuples, print an aligned table with a line total per row and a grand total.

Q50Functions & TuplesMedium

Write divide_with_remainder(a, b) that returns the quotient and remainder as a tuple, and use it inside a loop, unpacking the result each time.

Q51RecordsMediumMust Do

Ask how many students, collect a name and mark for each into a list of tuples, then print the class report with the average.

Q52CoordinatesMediumMust Do

Write distance(p1, p2) that takes two (x, y) tuples and returns the straight-line distance between them, without importing anything.

Q53CoordinatesMedium

Write midpoint(p1, p2) returning the halfway point as a tuple, and quadrant(point) returning which quadrant a point sits in.

Q54CoordinatesMedium

Given a list of (x, y) points, find the one closest to the origin and print it with its distance.

Q55RecordsMedium

Given a list of (name, r, g, b) colour tuples, print each colour's total brightness and name the brightest.

Q56RecordsMedium

Write format_date(date) that takes a (day, month, year) tuple and returns a string like 12 May 2001, and is_valid(date) that checks the day and month are in range.

Q57Functions & TuplesMediumMust Do

Write to_seconds(time) taking an (h, m, s) tuple, and to_hms(seconds) returning one. Show a round trip.

Q58RecordsMedium

Given a list of (item, quantity, unit_price) tuples, print the total value of the stock and the single most valuable line.

Q59SortingMedium

Given a list of (name, score) records, print a leaderboard sorted highest first, giving tied scores the same rank.

Q60Strings & TuplesMediumMust Do

Given a list of "name,age,city" strings, turn each into a tuple of three fields and print an aligned table.

Q61RecordsMedium

Given a list of (day, temperature) tuples, print the hottest day, the coldest day, and every day above the average.

Q62Nested TuplesMedium

Write transpose(grid) that takes a tuple of tuples and returns a new tuple of tuples with rows and columns swapped.

Q63RecordsMedium

Given a list of (name, department, salary) tuples, print the average salary and everyone earning above it.

Q64SearchingMediumMust Do

Given a list of records where some are exact duplicates, build a list of the unique ones keeping the original order, and report how many were dropped.

Q65RecordsMedium

Given two lists of (name, mark) records from two classes, merge them into one sorted list and print it with a running position number.

Q66RecordsMedium

Given a list of (title, author, year) book records, print only the books published after a year the user chooses.

Q67Strings & TuplesMedium

Given a list of full names as strings, build a list of (first, last) tuples and print them sorted by last name.

Q68RecordsMedium

Given (name, mark1, mark2, mark3) records, build a new list of (name, total, average, grade) tuples and print it as a table.

Q69Functions & TuplesMedium

Write summarise(records) that takes a list of (name, value) tuples and returns a tuple of (count, total, highest_name, lowest_name). Use it and unpack the result.

Q70FormattingMedium

Write print_table(headers, rows) where headers is a tuple of column names and rows is a list of tuples, sizing every column to its widest entry.

Q71ImmutabilityHardMust Do

A tuple is supposed to be unchangeable, yet this code changes one. Explain exactly what is and is not protected.

record = ("Asha", [88, 92])
record[1].append(79)
print(record)
Q72Single-Element TuplesHard

This function is meant to return a one-item tuple but returns something else entirely. Find the bug and show the fix.

def wrap(value):
    return (value)
 
result = wrap(5)
print(result)
print(type(result))
print(len(result))
Q73Single-Element TuplesHard

The opposite mistake: this is meant to store the number 5, but doubling it gives a strange answer. Explain and fix.

value = 5,
print(value)
print(value * 2)
Q74UnpackingHard

Write safe_unpack(record) that unpacks a (name, mark) record but reports a clear message when the record has the wrong number of fields, without letting the program crash.

Q75ImmutabilityHard

Show that += behaves differently on a tuple and a list, using id() to prove whether a new object was made.

Q76Tuple vs ListHardMust Do

Show that a tuple can be hashed but a list cannot, and explain in a comment why that difference is about to matter.

Q77ComparisonHard

Given a = (1, 2, 3) and b = (1, 2, 3), print a == b and a is b, then explain which one you should use and why the second might surprise you.

Q78ComparisonHard

Show that comparing tuples of different lengths works fine, but comparing tuples holding different types can fail. Explain the rule.

Q79DebuggingHard

This should print each student on a tidy line but prints brackets and quotes instead. Find and fix it.

records = [("Asha", 88), ("Raj", 74)]
 
for record in records:
    print(f"{record} scored well")
Q80DebuggingHard

This is meant to hold three records but len() says four. Find the bug.

records = [
    ("Asha", 88),
    ("Raj", 74),
    ("Meera", 91),
]
extra = [("Dev", 66)]
 
everyone = records + extra
print(len(everyone))
 
names = ("Asha"), ("Raj"), ("Meera")
print(len(names))
Q81SortingHardMust Do

Sort a list of (name, score) records by score descending, breaking ties by name ascending โ€” without using sorted(key=โ€ฆ).

Q82AlgorithmsHard

Given a list of (name, weight) records sorted by weight, use two pointers to find a pair whose weights add up exactly to a target.

Q83Nested TuplesHard

Write a recursive function flatten(data) that takes a tuple which may contain other tuples at any depth, and returns one flat tuple of all the values.

Q84SortingHard

Write sort_by_field(records, index) that sorts a list of tuples by any chosen position, using a selection sort you write yourself.

Q85Functions & TuplesHard

Design question. Write one function that returns a tuple and one that returns a list of the same data, then explain in comments which you would choose for a fixed set of results and why.

Q86Mini-ProjectMini-ProjectMust Do

Build a Student Records Manager. Offer a menu to add a (name, mark) record, list all records sorted by mark, show class statistics, and quit.

Q87Mini-ProjectMini-Project

Build a Contact Book holding (name, phone, email) tuples. Offer add, search by any part of a name, list all, and quit.

Q88Mini-ProjectMini-Project

Build a Coordinate Geometry Toolkit with distance(p1, p2), midpoint(p1, p2) and perimeter(points), then report on a shape the user describes.

Q89Mini-ProjectMini-Project

Build an Inventory Value Report from (item, quantity, unit_price) records: an aligned table with line totals, the grand total, the most valuable line, and a low-stock warning under 10 units.

Q90Mini-ProjectMini-ProjectMust Do

Build a Tournament Leaderboard. Read (player, wins, losses) records, compute points as 3 per win, and print a ranked table with win percentage, giving equal points the same rank.

Q91Nested TuplesMini-Project

Build a Timetable as a tuple of tuples โ€” one row per day, one column per period โ€” and print it as a grid, then report which day has the most free periods.

Q92Mini-ProjectMini-Project

Build a Movie Ratings Report from (title, year, rating) records: list them sorted by rating, show the average, and let the user filter by minimum rating.

Q93Mini-ProjectMini-Project

Build a Bank Transaction Log. Store each entry as a (kind, amount) tuple, keep a running balance, refuse an overdraft, and print a statement at the end.

Q94Nested TuplesMini-Project

Build a Distance Matrix. Store city names in a tuple and distances in a tuple of tuples, print the matrix as a grid, and report the closest pair of cities.

Q95Mini-ProjectMini-Project

Build an Election Vote Counter. Keep the candidates in a tuple, read votes until the user types done, reject invalid names, then print a tally sorted by votes with percentages and the winner.

Q96InterviewInterview

Compare tuples and lists properly: mutability, available methods, hashability, and what each one signals to a reader. Demonstrate every difference in code.

Q97PackingInterview

Packing and unpacking show up all over Python, often without brackets. Demonstrate every place you have now met, and name each one.

Q98ImmutabilityInterview

Explain why "tuples are immutable" is only half true. Show what is genuinely guaranteed, what is not, and how to build a fully frozen structure.

Q99RecordsInterview

Tuples make decent records until they grow. Show the same data as a tuple record and explain, with code, where positional records start to hurt and what fixes it.

Q100CapstoneInterviewMust Do

Capstone. Build a Tuple Toolkit Report. Read name,mark entries until the user types done, storing each as a tuple, then print one report showing the records, the same records sorted by mark and by name, the statistics as an unpacked tuple, the highest and lowest performers, any duplicate entries, and the records split into passed and failed.

Still stuck on something?

Book a free 1-on-1 session and we'll work through it together.

Book a Free Session