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

Swipe to show menu

book
Challenge: Boolean Logic

Ready to put everything you've learned into practice? This challenge will require you to use the and, or, and not operators as well as boolean comparison operators to manage a complex scenario for a grocery store.

Let's dive in!

Task

Swipe to start coding

Determine whether a grocery item should be discounted based on its seasonal status, stock level, and sales performance.

  • Define a boolean variable overstock_risk as True if the item is seasonal and its current_stock exceeds the high_stock_threshold.
  • Define another boolean variable discount_eligible as True if the item is not selling_well and is not already on_sale.
  • Create a boolean variable make_discount that is True if either overstock_risk or discount_eligible is True.

Output Requirements

  • Print whether the item should be discounted: Should the item be discounted? <make_discount>.

Requirements checklist

  1. Check that the value of overstock_risk is True if seasonal is True and current_stock is greater than high_stock_threshold.
  2. Check that the value of discount_eligible is True if selling_well is False and on_sale is False.
  3. Check that make_discount is True if either overstock_risk or discount_eligible is True.
  4. Check that the printed output contains "Should the item be discounted?" followed by the value of make_discount.

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Β 3
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: Boolean Logic

Ready to put everything you've learned into practice? This challenge will require you to use the and, or, and not operators as well as boolean comparison operators to manage a complex scenario for a grocery store.

Let's dive in!

Task

Swipe to start coding

Determine whether a grocery item should be discounted based on its seasonal status, stock level, and sales performance.

  • Define a boolean variable overstock_risk as True if the item is seasonal and its current_stock exceeds the high_stock_threshold.
  • Define another boolean variable discount_eligible as True if the item is not selling_well and is not already on_sale.
  • Create a boolean variable make_discount that is True if either overstock_risk or discount_eligible is True.

Output Requirements

  • Print whether the item should be discounted: Should the item be discounted? <make_discount>.

Requirements checklist

  1. Check that the value of overstock_risk is True if seasonal is True and current_stock is greater than high_stock_threshold.
  2. Check that the value of discount_eligible is True if selling_well is False and on_sale is False.
  3. Check that make_discount is True if either overstock_risk or discount_eligible is True.
  4. Check that the printed output contains "Should the item be discounted?" followed by the value of make_discount.

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