0
0
Pythonprogramming~15 mins

Tuple unpacking in Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Tuple Unpacking with Product Data
๐Ÿ“– Scenario: You work in a store and have a list of products. Each product is stored as a tuple with its name, price, and quantity.
๐ŸŽฏ Goal: You will learn how to use tuple unpacking to easily get each piece of information from the product tuples.
๐Ÿ“‹ What You'll Learn
Create a list of product tuples with exact values
Create a variable to count total items in stock
Use tuple unpacking in a for loop to get product details
Print the total number of items in stock
๐Ÿ’ก Why This Matters
๐ŸŒ Real World
Stores and warehouses often keep product data as tuples or lists. Tuple unpacking helps quickly access each piece of information.
๐Ÿ’ผ Career
Knowing tuple unpacking is useful for data processing tasks in jobs like inventory management, data analysis, and software development.
Progress0 / 4 steps
1
Create the product list
Create a list called products with these exact tuples: ("Apple", 0.5, 10), ("Banana", 0.3, 20), and ("Orange", 0.7, 15).
Python
Need a hint?

Use square brackets [] to create a list and parentheses () for each product tuple.

2
Create a total count variable
Create a variable called total_quantity and set it to 0 to hold the total number of items in stock.
Python
Need a hint?

Just write total_quantity = 0 on a new line.

3
Use tuple unpacking in a loop
Use a for loop with tuple unpacking to get name, price, and quantity from each product in products. Inside the loop, add quantity to total_quantity.
Python
Need a hint?

Write for name, price, quantity in products: and inside add quantity to total_quantity.

4
Print the total quantity
Write a print statement to display the text Total items in stock: followed by the value of total_quantity.
Python
Need a hint?

Use an f-string like print(f"Total items in stock: {total_quantity}").