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)
course content

Kursinnhold

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

Oppgave

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 desktopBytt til skrivebordet for virkelighetspraksisFortsett der du er med et av alternativene nedenfor
Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 4. Kapittel 8
toggle bottom row

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.

Oppgave

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 desktopBytt til skrivebordet for virkelighetspraksisFortsett der du er med et av alternativene nedenfor
Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 4. Kapittel 8
Switch to desktopBytt til skrivebordet for virkelighetspraksisFortsett der du er med et av alternativene nedenfor
Vi beklager at noe gikk galt. Hva skjedde?
some-alt