Challenge: Automating Stock Control
When working with lists, you can assign multiple values to separate variables in a single line. Each variable receives the value in the corresponding position:
name, age, city = ["Alex", 25, "London"]
In the same way, the values stored for an inventory item can be assigned to separate variables:
current_stock, min_stock, restock_amount, on_sale = inventory[item]
Thanks for your feedback!
single
Challenge: Automating Stock Control
Swipe to show menu
When working with lists, you can assign multiple values to separate variables in a single line. Each variable receives the value in the corresponding position:
name, age, city = ["Alex", 25, "London"]
In the same way, the values stored for an inventory item can be assigned to separate variables:
current_stock, min_stock, restock_amount, on_sale = inventory[item]
Swipe to start coding
You are managing a grocery store inventory. Restock any item that falls below its minimum stock level. If an item's stock rises above the discount threshold, mark it as on sale.
- Use a
forloop to process each item in theinventorydictionary. - For each item:
- Use a
whileloop to increase the stock by the restock quantity until it reaches the minimum required stock. - Save the updated stock in the dictionary.
- If the stock is above
discount_thresholdand the item is not on sale, set its sale status toTrue.
- Use a
Solution
Thanks for your feedback!
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat