Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge: Product Management Capstone | Conditional Statements
Introduction to Python (generated task tests)

Swipe to show menu

book
Challenge: Product Management Capstone

Congratulations on reaching this point in the course! In this capstone challenge, you will manage perishable products at a grocery store, determining discounts based on product expiration and stock levels. Your goal is to minimize waste while effectively maximizing sales through strategic discounting.

Let's see how well you can translate business rules into Python code!

Scenario

As a manager at a grocery store, you are responsible for implementing a discount strategy for perishable products based on their expiration date and stock levels.

The discount strategy is as follows:

  • Apply a 30% discount if the product expires in 3 days or less and the stock level is over50 units;

  • Apply a 20% discount if the product expires in 4 to 6 days and the stock level is over50 units;

  • Apply a 10% discount if the product expires in 7 days or more, or if the stock level is 50 units or less;

  • No discount if the product is not "Perishable".

Task

Swipe to start coding

Implement a series of conditional statements to determine the discount for a product based on its type, days until expiration, and stock level.

  • Start by checking if the product_type is "Perishable".
  • Inside this if statement:
    • Apply a 30% discount if days_until_expiration is 3 or less and stock_level is greater than 50;
    • Use elif to apply a 20% discount if days_until_expiration is between 4 and 6, and stock_level is greater than 50;
    • Use another elif to apply a 10% discount if days_until_expiration is greater than 6 and stock_level is 50 or less.
  • If the product_type is not "Perishable", print "No discount available for non-perishable items.".

Output Requirements

  • If a 30% discount is applied, print: "30% discount applied"
  • If a 20% discount is applied, print: "20% discount applied"
  • If a 10% discount is applied, print: "10% discount applied"
  • If the product is non-perishable, print: "No discount available for non-perishable items."

Note

You can nest multiple if statements within each other. Be sure to manage the indentation properly for each block.

Requirements checklist

  1. Set product_type to "Perishable", days_until_expiration to 2, stock_level to 51. Check that "30% discount applied" is printed.
  2. Set product_type to "Perishable", days_until_expiration to 4, stock_level to 60. Check that "20% discount applied" is printed.
  3. Set product_type to "Perishable", days_until_expiration to 6, stock_level to 51. Check that "20% discount applied" is printed.
  4. Set product_type to "Perishable", days_until_expiration to 7, stock_level to 50. Check that "10% discount applied" is printed.
  5. Set product_type to "Perishable", days_until_expiration to 8, stock_level to 40. Check that "10% discount applied" is printed.
  6. Set product_type to "Perishable", days_until_expiration to 3, stock_level to 50. Check that nothing is printed.
  7. Set product_type to "Non-Perishable", days_until_expiration to any value, stock_level to any value. Check that "No discount available for non-perishable items." is printed.

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Β 3. ChapterΒ 6
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: Product Management Capstone

Congratulations on reaching this point in the course! In this capstone challenge, you will manage perishable products at a grocery store, determining discounts based on product expiration and stock levels. Your goal is to minimize waste while effectively maximizing sales through strategic discounting.

Let's see how well you can translate business rules into Python code!

Scenario

As a manager at a grocery store, you are responsible for implementing a discount strategy for perishable products based on their expiration date and stock levels.

The discount strategy is as follows:

  • Apply a 30% discount if the product expires in 3 days or less and the stock level is over50 units;

  • Apply a 20% discount if the product expires in 4 to 6 days and the stock level is over50 units;

  • Apply a 10% discount if the product expires in 7 days or more, or if the stock level is 50 units or less;

  • No discount if the product is not "Perishable".

Task

Swipe to start coding

Implement a series of conditional statements to determine the discount for a product based on its type, days until expiration, and stock level.

  • Start by checking if the product_type is "Perishable".
  • Inside this if statement:
    • Apply a 30% discount if days_until_expiration is 3 or less and stock_level is greater than 50;
    • Use elif to apply a 20% discount if days_until_expiration is between 4 and 6, and stock_level is greater than 50;
    • Use another elif to apply a 10% discount if days_until_expiration is greater than 6 and stock_level is 50 or less.
  • If the product_type is not "Perishable", print "No discount available for non-perishable items.".

Output Requirements

  • If a 30% discount is applied, print: "30% discount applied"
  • If a 20% discount is applied, print: "20% discount applied"
  • If a 10% discount is applied, print: "10% discount applied"
  • If the product is non-perishable, print: "No discount available for non-perishable items."

Note

You can nest multiple if statements within each other. Be sure to manage the indentation properly for each block.

Requirements checklist

  1. Set product_type to "Perishable", days_until_expiration to 2, stock_level to 51. Check that "30% discount applied" is printed.
  2. Set product_type to "Perishable", days_until_expiration to 4, stock_level to 60. Check that "20% discount applied" is printed.
  3. Set product_type to "Perishable", days_until_expiration to 6, stock_level to 51. Check that "20% discount applied" is printed.
  4. Set product_type to "Perishable", days_until_expiration to 7, stock_level to 50. Check that "10% discount applied" is printed.
  5. Set product_type to "Perishable", days_until_expiration to 8, stock_level to 40. Check that "10% discount applied" is printed.
  6. Set product_type to "Perishable", days_until_expiration to 3, stock_level to 50. Check that nothing is printed.
  7. Set product_type to "Non-Perishable", days_until_expiration to any value, stock_level to any value. Check that "No discount available for non-perishable items." is printed.

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