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

bookChallenge: Automating Stock Control

You are managing the inventory for a grocery store, and your task is to ensure that the stock for each product is properly maintained and restocked when necessary.

If an item's stock level falls below the minimum required amount, it needs to be restocked.

Additionally, if the stock level of an item exceeds a certain threshold, a discount is applied, and the item is marked as "on sale."

Task

Swipe to start coding

Goal

Manage grocery store inventory by restocking items using a while loop and applying discounts based on stock levels. You will use loops to update each item status.

Rules

  1. Use a for loop to go through each item in the inventory dictionary.

    • For each item, get its current stock, minimum required stock, restock quantity, and sale status.
  2. Use a while loop to restock the item until its stock is at or above the minimum.

    • Increase the stock by the restock quantity on each iteration.
    • Update the stock value in the dictionary after restocking.
  3. After restocking, check if the stock exceeds the discount_threshold and the item is not yet on sale.

    • If so, set its sale status to True and print a discount message.
    • If the item is already on sale and still exceeds the threshold, print a message that it is already discounted.

Output Requirements

  • Before any processing starts, print a line containing the word Processing, for example Processing started

  • For each item, print messages in the following order

    1. A header line containing the word Processing and the item name Example Processing Bread...

    2. If restocking occurred, print a line describing the new stock and the minimum required Example Bread was restocked to 50 min required 50

    3. Discount information

      • If a discount is applied, print a line mentioning Discount applied and the item name Example Bread stock has exceeded 100 units. Discount applied.
      • If the item is already on sale, print a line that says it is already discounted Example Bread is already discounted.
    4. A footer line containing the word Processing and the item name Example Processing complete for Bread

  • After all items are processed, print a final summary line containing the word Processing Example Processing summary: completed

  • Then print the final inventory report with the header Final Inventory Report

  • For each item, print one line showing its current stock, minimum stock, and sale status in the following format Bread: 50 units Min 50 units - On sale: False

Flexibility Notes

  • Keep the order of outputs exactly as described.
  • Exact punctuation and capitalization do not matter.
  • The word Processing must appear several times in the output: in the global start, per-item header, per-item footer, and final summary.

Solution

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

Suggested prompts:

What is the minimum required stock level for each product?

What is the threshold for applying a discount and marking an item as "on sale"?

Can you provide an example of how to manage the inventory for a specific product?

close

Awesome!

Completion rate improved to 2.17

bookChallenge: Automating Stock Control

Swipe to show menu

You are managing the inventory for a grocery store, and your task is to ensure that the stock for each product is properly maintained and restocked when necessary.

If an item's stock level falls below the minimum required amount, it needs to be restocked.

Additionally, if the stock level of an item exceeds a certain threshold, a discount is applied, and the item is marked as "on sale."

Task

Swipe to start coding

Goal

Manage grocery store inventory by restocking items using a while loop and applying discounts based on stock levels. You will use loops to update each item status.

Rules

  1. Use a for loop to go through each item in the inventory dictionary.

    • For each item, get its current stock, minimum required stock, restock quantity, and sale status.
  2. Use a while loop to restock the item until its stock is at or above the minimum.

    • Increase the stock by the restock quantity on each iteration.
    • Update the stock value in the dictionary after restocking.
  3. After restocking, check if the stock exceeds the discount_threshold and the item is not yet on sale.

    • If so, set its sale status to True and print a discount message.
    • If the item is already on sale and still exceeds the threshold, print a message that it is already discounted.

Output Requirements

  • Before any processing starts, print a line containing the word Processing, for example Processing started

  • For each item, print messages in the following order

    1. A header line containing the word Processing and the item name Example Processing Bread...

    2. If restocking occurred, print a line describing the new stock and the minimum required Example Bread was restocked to 50 min required 50

    3. Discount information

      • If a discount is applied, print a line mentioning Discount applied and the item name Example Bread stock has exceeded 100 units. Discount applied.
      • If the item is already on sale, print a line that says it is already discounted Example Bread is already discounted.
    4. A footer line containing the word Processing and the item name Example Processing complete for Bread

  • After all items are processed, print a final summary line containing the word Processing Example Processing summary: completed

  • Then print the final inventory report with the header Final Inventory Report

  • For each item, print one line showing its current stock, minimum stock, and sale status in the following format Bread: 50 units Min 50 units - On sale: False

Flexibility Notes

  • Keep the order of outputs exactly as described.
  • Exact punctuation and capitalization do not matter.
  • The word Processing must appear several times in the output: in the global start, per-item header, per-item footer, and final summary.

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

some-alt