Section 3. Chapter 3
single
Challenge: Boolean Logic
Swipe to show menu
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— it should beTrueif the item isseasonaland itscurrent_stockexceedshigh_stock_threshold. - Define a boolean variable
discount_eligible— it should beTrueif the item is notselling_welland noton_sale. - Define a boolean variable
make_discount— it should beTrueif eitheroverstock_riskordiscount_eligibleisTrue.
Output: Print the following line, where the value of make_discount is shown at the end:
Should the item be discounted? True
Solution
Everything was clear?
Thanks for your feedback!
Section 3. Chapter 3
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat