Cursusinhoud
Introduction to Python (copy)
Introduction to Python (copy)
Challenge: Pricing Adjustment Capstone
You are managing a grocery store's system, and you need to maintain decision-making for the inventory, track prices, and perform checks to determine if actions like restocking or removing items from the inventory are needed based on their price or stock.
Swipe to start coding
Manage a grocery inventory using a dictionary in Python. Perform operations like updating prices, adding new items, and managing stock levels based on conditions.
-
Complete the Dictionary: Define
grocery_inventory
with the following items and their details:"Milk"
:("Dairy", 3.50, 8)
"Eggs"
:("Dairy", 5.50, 30)
"Bread"
:("Bakery", 2.99, 15)
"Apples"
:("Produce", 1.50, 50)
-
Check and Update Price:
- Retrieve the price of
"Eggs"
. If the price is greater than $5, print"Eggs are too expensive, reducing the price by $1."
and reduce the price by $1. Otherwise, print"The price of Eggs is reasonable."
.
- Retrieve the price of
-
Add a New Item:
- Add
"Tomatoes"
with details: category"Produce"
, price $1.20, and stock30
.
- Add
-
Manage Stock:
- Check the stock of
"Milk"
. If it's less than10
, print"Milk needs to be restocked. Increasing stock by 20 units."
and increase the stock by20
. Otherwise, print"Milk has sufficient stock."
.
- Check the stock of
-
Remove Item Based on Price:
- Check the price of
"Apples"
. If it exceeds $2, remove"Apples"
from the inventory and print"Apples removed from inventory due to high price."
.
- Check the price of
Output Requirements
-
When checking
"Eggs"
' price, print:"Eggs are too expensive, reducing the price by $1."
if the price is greater than $5."The price of Eggs is reasonable."
if the price is $5 or less.
-
After adding
"Tomatoes"
, print the updated inventory:"Inventory after adding Tomatoes: <$grocery_inventory>"
. -
When checking
"Milk"
stock, print:"Milk needs to be restocked. Increasing stock by 20 units."
if the stock is less than10
."Milk has sufficient stock."
if the stock is10
or more.
-
If
"Apples"
are removed, print"Apples removed from inventory due to high price."
. -
Finally, print the updated inventory:
"Updated inventory: <$grocery_inventory>"
.
Note
Use square brackets to access values from tuples in the dictionary, e.g.,
inventory["Bread"][1]
to get the price of"Bread"
.
Oplossing
Bedankt voor je feedback!
Challenge: Pricing Adjustment Capstone
You are managing a grocery store's system, and you need to maintain decision-making for the inventory, track prices, and perform checks to determine if actions like restocking or removing items from the inventory are needed based on their price or stock.
Swipe to start coding
Manage a grocery inventory using a dictionary in Python. Perform operations like updating prices, adding new items, and managing stock levels based on conditions.
-
Complete the Dictionary: Define
grocery_inventory
with the following items and their details:"Milk"
:("Dairy", 3.50, 8)
"Eggs"
:("Dairy", 5.50, 30)
"Bread"
:("Bakery", 2.99, 15)
"Apples"
:("Produce", 1.50, 50)
-
Check and Update Price:
- Retrieve the price of
"Eggs"
. If the price is greater than $5, print"Eggs are too expensive, reducing the price by $1."
and reduce the price by $1. Otherwise, print"The price of Eggs is reasonable."
.
- Retrieve the price of
-
Add a New Item:
- Add
"Tomatoes"
with details: category"Produce"
, price $1.20, and stock30
.
- Add
-
Manage Stock:
- Check the stock of
"Milk"
. If it's less than10
, print"Milk needs to be restocked. Increasing stock by 20 units."
and increase the stock by20
. Otherwise, print"Milk has sufficient stock."
.
- Check the stock of
-
Remove Item Based on Price:
- Check the price of
"Apples"
. If it exceeds $2, remove"Apples"
from the inventory and print"Apples removed from inventory due to high price."
.
- Check the price of
Output Requirements
-
When checking
"Eggs"
' price, print:"Eggs are too expensive, reducing the price by $1."
if the price is greater than $5."The price of Eggs is reasonable."
if the price is $5 or less.
-
After adding
"Tomatoes"
, print the updated inventory:"Inventory after adding Tomatoes: <$grocery_inventory>"
. -
When checking
"Milk"
stock, print:"Milk needs to be restocked. Increasing stock by 20 units."
if the stock is less than10
."Milk has sufficient stock."
if the stock is10
or more.
-
If
"Apples"
are removed, print"Apples removed from inventory due to high price."
. -
Finally, print the updated inventory:
"Updated inventory: <$grocery_inventory>"
.
Note
Use square brackets to access values from tuples in the dictionary, e.g.,
inventory["Bread"][1]
to get the price of"Bread"
.
Oplossing
Bedankt voor je feedback!