LearnFrenzy
Sign in Take a free test

Tuples · Exercise 4 of 4

Tuples Tuples Coding Problems

  • 10 questions
  • Page 1 of 1
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

Python programs built on tuples, unpacking and namedtuple. Write each one yourself first, then open the solution – every solution was run on Python 3, the output shown is the real output, and Run opens it in the online Python compiler.

Question 1 Easy

Rotate three variables so that a gets b's value, b gets c's and c gets a's, in one statement, three times.

Question page & discussion
Question 2 Easy

Write a function that returns the lowest mark, the highest mark and the average (two decimals) of a list, and print them for each class.

Question page & discussion
Question 3 Medium

Students are (name, branch, marks) tuples. Print them sorted by branch, and within a branch by marks from high to low.

Question page & discussion
Question 4 Medium

Store employees as namedtuples and print the total and average salary per department, and the highest-paid employee.

Question page & discussion
Question 5 Medium

Given (city, temperature) pairs, split them into a tuple of cities and a tuple of temperatures, then print the hottest city.

Question page & discussion
Question 6 Medium

A matrix is a tuple of row tuples. Print its transpose and check that transposing twice gives the original.

Question page & discussion
Question 7 Easy

Remove duplicate items from a tuple, keep the first occurrence of each, and return a tuple. Also report which items were repeated.

Question page & discussion
Question 8 Easy

From a list of tuples, keep only those whose every element is divisible by k = 3.

Question page & discussion
Question 9 Hard

A robot starts at (0, 0) and follows the moves U, D, L, R. Count how often each cell is visited, using (x, y) tuples as dictionary keys, and print the cells visited more than once.

Question page & discussion
Question 10 Medium

Dates are (year, month, day) tuples. Sort the exam dates, find the earliest one after 1 March 2027, and print them as DD-MM-YYYY.

Question page & discussion
All exercises doneBack to TuplesRevise the concepts or pick another topic

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links