← All Exercises

Python Tuple Unpacking

basicpython~10min

Background

Tuple unpacking provides a concise way to extract multiple values, and the star expression handles variable-length sequences.

Problem

Write a function that takes a tuple of scores and returns the first, last, and average of middle scores using extended unpacking.

Input

A tuple of numbers with at least 3 elements.

Output

A tuple of (first, last, average_of_middle).

Sample tests

Sample 1

Input: (10, 20, 30, 40, 50)
Expected: (10, 50, 30.0)

Your solution

Learning objective

Learn tuple unpacking with the star expression for variable-length extraction.