Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ Challenge: Automating Stock Control | Loops
Introduction to Python (generated task tests)
セクション 5.  7
single

single

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."

タスク

スワイプしてコーディングを開始

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>

Requirements checklist

  1. For each item in the inventory, after processing, the item's stock must be greater than or equal to its minimum required stock.
  2. For each item, after processing, the item's stock must be equal to its original stock plus enough restock increments (if any) to reach at least the minimum required stock.
  3. For each item, if its final stock is greater than the discount threshold and it was not on sale before, its sale status must be set to True.
  4. For each item, if its final stock is less than or equal to the discount threshold, its sale status must remain unchanged from its original value.
  5. After processing all items, the program must print "Final Inventory Report".
  6. For each item, the program must print a line in the format: ": <current_stock> units (Min: <min_stock> units) - On sale: <on_sale>".
  7. For each item, the program must print "Processing ..." before processing that item.
  8. If a discount is applied to an item, the program must print " stock has exceeded <discount_threshold> units. Discount applied." If the item is already discounted and still exceeds the threshold, the program must print " is already discounted."

解答

Switch to desktop実践的な練習のためにデスクトップに切り替える下記のオプションのいずれかを利用して、現在の場所から続行する
すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 5.  7
single

single

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

some-alt