0
0
Pythonprogramming~15 mins

Adding and updating key-value pairs in Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Adding and updating key-value pairs
๐Ÿ“– Scenario: You are managing a small store's inventory. You need to keep track of the products and their quantities using a dictionary.
๐ŸŽฏ Goal: Create a dictionary with initial products and quantities, add a new product, update the quantity of an existing product, and then display the final inventory.
๐Ÿ“‹ What You'll Learn
Create a dictionary called inventory with exact products and quantities
Add a new product with a specific quantity to inventory
Update the quantity of an existing product in inventory
Print the final inventory dictionary
๐Ÿ’ก Why This Matters
๐ŸŒ Real World
Managing inventory is a common task in stores and warehouses to keep track of product quantities.
๐Ÿ’ผ Career
Knowing how to add and update key-value pairs in dictionaries is essential for data management and software development.
Progress0 / 4 steps
1
Create the initial inventory dictionary
Create a dictionary called inventory with these exact entries: 'apples': 10, 'bananas': 5, and 'oranges': 8.
Python
Need a hint?

Use curly braces {} to create a dictionary with keys and values separated by colons.

2
Add a new product to the inventory
Add a new product 'pears' with quantity 12 to the inventory dictionary.
Python
Need a hint?

Use square brackets [] with the new key to add it to the dictionary.

3
Update the quantity of an existing product
Update the quantity of 'bananas' in the inventory dictionary to 7.
Python
Need a hint?

Use the key 'bananas' with square brackets to assign the new quantity.

4
Display the final inventory
Print the inventory dictionary to show all products and their quantities.
Python
Need a hint?

Use the print() function to display the dictionary.