Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lära Challenge: Automating Stock Control | Loops
Introduction to Python (copy)
course content

Kursinnehåll

Introduction to Python (copy)

Introduction to Python (copy)

1. Getting Started
2. Variables and Types
3. Conditional Statements
4. Other Data Types
5. Loops
6. Functions

book
Challenge: 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."

Uppgift

Swipe to start coding

Manage grocery store inventory by restocking items and applying discounts based on stock levels. You'll use loops to update each item's status.

  • 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.
  • 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.
  • After restocking, check if the stock exceeds discount_threshold and the item is not yet on sale. If so, set its sale status to True.
  • If the item is already on sale and still exceeds the threshold, print a message indicating it is already discounted.

Output Requirements

  • For each item, print:
    Processing <item>...
  • If a discount is applied:
    <item> stock has exceeded <discount_threshold> units. Discount applied.
  • If the item is already on sale:
    <item> is already discounted.
  • After all items are processed, print:
    Final Inventory Report
    Then, for each item:
    <Item>: <current_stock> units (Min: <min_stock> units) - On sale: <on_sale>

Lösning

Switch to desktopByt till skrivbordet för praktisk övningFortsätt där du är med ett av alternativen nedan
Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 5. Kapitel 7
toggle bottom row

book
Challenge: 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."

Uppgift

Swipe to start coding

Manage grocery store inventory by restocking items and applying discounts based on stock levels. You'll use loops to update each item's status.

  • 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.
  • 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.
  • After restocking, check if the stock exceeds discount_threshold and the item is not yet on sale. If so, set its sale status to True.
  • If the item is already on sale and still exceeds the threshold, print a message indicating it is already discounted.

Output Requirements

  • For each item, print:
    Processing <item>...
  • If a discount is applied:
    <item> stock has exceeded <discount_threshold> units. Discount applied.
  • If the item is already on sale:
    <item> is already discounted.
  • After all items are processed, print:
    Final Inventory Report
    Then, for each item:
    <Item>: <current_stock> units (Min: <min_stock> units) - On sale: <on_sale>

Lösning

Switch to desktopByt till skrivbordet för praktisk övningFortsätt där du är med ett av alternativen nedan
Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 5. Kapitel 7
Switch to desktopByt till skrivbordet för praktisk övningFortsätt där du är med ett av alternativen nedan
Vi beklagar att något gick fel. Vad hände?
some-alt