Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Challenge: Pricing Adjustment Capstone | Other Data Types
Introduction to Python (copy)

Stryg for at vise menuen

book
Challenge: Pricing Adjustment Capstone

You are managing a grocery store's system, and you need to maintain decision-making for the inventory, track prices, and perform checks to determine if actions like restocking or removing items from the inventory are needed based on their price or stock.

Opgave

Swipe to start coding

Manage a grocery inventory using a dictionary in Python. Perform operations like updating prices, adding new items, and managing stock levels based on conditions.

  1. Complete the Dictionary: Define grocery_inventory with the following items and their details:

    • "Milk": ("Dairy", 3.50, 8)
    • "Eggs": ("Dairy", 5.50, 30)
    • "Bread": ("Bakery", 2.99, 15)
    • "Apples": ("Produce", 1.50, 50)
  2. Check and Update Price:

    • Retrieve the price of "Eggs". If the price is greater than $5, print "Eggs are too expensive, reducing the price by $1." and reduce the price by $1. Otherwise, print "The price of Eggs is reasonable.".
  3. Add a New Item:

    • Add "Tomatoes" with details: category "Produce", price $1.20, and stock 30.
  4. Manage Stock:

    • Check the stock of "Milk". If it's less than 10, print "Milk needs to be restocked. Increasing stock by 20 units." and increase the stock by 20. Otherwise, print "Milk has sufficient stock.".
  5. Remove Item Based on Price:

    • Check the price of "Apples". If it exceeds $2, remove "Apples" from the inventory and print "Apples removed from inventory due to high price.".

Output Requirements

  • When checking "Eggs"' price, print:

    • "Eggs are too expensive, reducing the price by $1." if the price is greater than $5.
    • "The price of Eggs is reasonable." if the price is $5 or less.
  • After adding "Tomatoes", print the updated inventory: "Inventory after adding Tomatoes: <$grocery_inventory>".

  • When checking "Milk" stock, print:

    • "Milk needs to be restocked. Increasing stock by 20 units." if the stock is less than 10.
    • "Milk has sufficient stock." if the stock is 10 or more.
  • If "Apples" are removed, print "Apples removed from inventory due to high price.".

  • Finally, print the updated inventory: "Updated inventory: <$grocery_inventory>".

Note

Use square brackets to access values from tuples in the dictionary, e.g., inventory["Bread"][1] to get the price of "Bread".

Løsning

Switch to desktopSkift til skrivebord for at øve i den virkelige verdenFortsæt der, hvor du er, med en af nedenstående muligheder
Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 4. Kapitel 8

Spørg AI

expand
ChatGPT

Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat

book
Challenge: Pricing Adjustment Capstone

You are managing a grocery store's system, and you need to maintain decision-making for the inventory, track prices, and perform checks to determine if actions like restocking or removing items from the inventory are needed based on their price or stock.

Opgave

Swipe to start coding

Manage a grocery inventory using a dictionary in Python. Perform operations like updating prices, adding new items, and managing stock levels based on conditions.

  1. Complete the Dictionary: Define grocery_inventory with the following items and their details:

    • "Milk": ("Dairy", 3.50, 8)
    • "Eggs": ("Dairy", 5.50, 30)
    • "Bread": ("Bakery", 2.99, 15)
    • "Apples": ("Produce", 1.50, 50)
  2. Check and Update Price:

    • Retrieve the price of "Eggs". If the price is greater than $5, print "Eggs are too expensive, reducing the price by $1." and reduce the price by $1. Otherwise, print "The price of Eggs is reasonable.".
  3. Add a New Item:

    • Add "Tomatoes" with details: category "Produce", price $1.20, and stock 30.
  4. Manage Stock:

    • Check the stock of "Milk". If it's less than 10, print "Milk needs to be restocked. Increasing stock by 20 units." and increase the stock by 20. Otherwise, print "Milk has sufficient stock.".
  5. Remove Item Based on Price:

    • Check the price of "Apples". If it exceeds $2, remove "Apples" from the inventory and print "Apples removed from inventory due to high price.".

Output Requirements

  • When checking "Eggs"' price, print:

    • "Eggs are too expensive, reducing the price by $1." if the price is greater than $5.
    • "The price of Eggs is reasonable." if the price is $5 or less.
  • After adding "Tomatoes", print the updated inventory: "Inventory after adding Tomatoes: <$grocery_inventory>".

  • When checking "Milk" stock, print:

    • "Milk needs to be restocked. Increasing stock by 20 units." if the stock is less than 10.
    • "Milk has sufficient stock." if the stock is 10 or more.
  • If "Apples" are removed, print "Apples removed from inventory due to high price.".

  • Finally, print the updated inventory: "Updated inventory: <$grocery_inventory>".

Note

Use square brackets to access values from tuples in the dictionary, e.g., inventory["Bread"][1] to get the price of "Bread".

Løsning

Switch to desktopSkift til skrivebord for at øve i den virkelige verdenFortsæt der, hvor du er, med en af nedenstående muligheder
Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 4. Kapitel 8
Switch to desktopSkift til skrivebord for at øve i den virkelige verdenFortsæt der, hvor du er, med en af nedenstående muligheder
Vi beklager, at noget gik galt. Hvad skete der?
some-alt