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

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's status, but only print a simple processing message for each item and a final summary.

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, if the stock exceeds discount_threshold and the item is not on sale, set its sale status to True in the dictionary.

Output Requirements

  • Before the loop starts, print a line containing the word Processing (for example: Processing started).
  • For each item, print a single line: Processing [item name] (for example: Processing Bread).
  • After all items are processed, print a summary line containing the word Processing (for example: Processing completed).

Do not print details about restocking or discount application. Do not print a final inventory report. Only print the required processing lines.

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

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

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's status, but only print a simple processing message for each item and a final summary.

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, if the stock exceeds discount_threshold and the item is not on sale, set its sale status to True in the dictionary.

Output Requirements

  • Before the loop starts, print a line containing the word Processing (for example: Processing started).
  • For each item, print a single line: Processing [item name] (for example: Processing Bread).
  • After all items are processed, print a summary line containing the word Processing (for example: Processing completed).

Do not print details about restocking or discount application. Do not print a final inventory report. Only print the required processing lines.

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