Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge: Pricing Adjustment Capstone | Other Data Types
Introduction to Python (generated task tests)

Swipe to show menu

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.

Task

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

Requirements checklist

  1. Check that after execution, the value of grocery_inventory["Eggs"][1] is exactly $4.50 (i.e., $5.50 - $1), since the original price was $5.50 and should be reduced by $1.
  2. Check that grocery_inventory contains a key "Tomatoes" with value ("Produce", 1.20, 30) after execution.
  3. Check that after execution, the value of grocery_inventory["Milk"][2] is exactly 28 (i.e., 8 + 20), since the original stock was 8 and should be increased by 20.
  4. Check that "Apples" is still present in grocery_inventory after execution and its value is unchanged, since its price ($1.50) does not exceed $2.
  5. Check that the final value of grocery_inventory["Bread"] is unchanged and equals ("Bakery", 2.99, 15).
  6. Check that the final value of grocery_inventory["Milk"][1] is still $3.50 (the price of milk is not changed).
  7. Check that the final value of grocery_inventory["Eggs"][0] is "Dairy" (the category is unchanged).
  8. Check that the final value of grocery_inventory["Tomatoes"][2] is 30 (the stock of tomatoes is correct).

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Β 4. ChapterΒ 8
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

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.

Task

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

Requirements checklist

  1. Check that after execution, the value of grocery_inventory["Eggs"][1] is exactly $4.50 (i.e., $5.50 - $1), since the original price was $5.50 and should be reduced by $1.
  2. Check that grocery_inventory contains a key "Tomatoes" with value ("Produce", 1.20, 30) after execution.
  3. Check that after execution, the value of grocery_inventory["Milk"][2] is exactly 28 (i.e., 8 + 20), since the original stock was 8 and should be increased by 20.
  4. Check that "Apples" is still present in grocery_inventory after execution and its value is unchanged, since its price ($1.50) does not exceed $2.
  5. Check that the final value of grocery_inventory["Bread"] is unchanged and equals ("Bakery", 2.99, 15).
  6. Check that the final value of grocery_inventory["Milk"][1] is still $3.50 (the price of milk is not changed).
  7. Check that the final value of grocery_inventory["Eggs"][0] is "Dairy" (the category is unchanged).
  8. Check that the final value of grocery_inventory["Tomatoes"][2] is 30 (the stock of tomatoes is correct).

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!

close

Awesome!

Completion rate improved to 2.17

Swipe to show menu

some-alt