Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge: Automating Stock Control | Loops
Introduction to Python

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]
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 5. Chapter 7
single

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]
Task

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 for loop to process each item in the inventory dictionary.
  • For each item:
    • Use a while loop 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_threshold and the item is not on sale, set its sale status to True.

Solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 5. Chapter 7
single

single

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

some-alt