Editor

Loop and Unpack Student Scores

Intermediate · Write the code · from Python Tuples: When and Why to Use Immutable Sequences

From the lesson: Python Tuples: When and Why to Use Immutable Sequences

Think about GPS coordinates. A location like (40.7128, -74.0060) represents New York City. If you accidentally changed one of those numbers, the location would point somewhere completely different. Some data simply should not change after you create it.

Read the lesson

You have a list of tuples, where each tuple contains a student name and their score. Loop through the list, unpack each tuple, and print each student's result in this format:

Alice: 92
Bob: 85
Charlie: 78
students = [
('Alice', 92),
('Bob', 85),
('Charlie', 78),
]
# Loop through and print each student's result

More Tuples exercises

All Python exercises · 50 practice problems · Data Structures quiz