Uitdaging: Booleaanse Logica
Klaar om alles wat je hebt geleerd in de praktijk te brengen? Deze uitdaging vereist het gebruik van de and
, or
en not
operatoren evenals booleaanse vergelijkingsoperatoren om een complex scenario voor een supermarkt te beheren.
Laten we beginnen!
Taak
Swipe to start coding
Bepaal of een levensmiddel in aanmerking komt voor korting op basis van de seizoensstatus, het voorraadniveau en de verkoopprestaties.
- Definieer een booleaanse variabele
overstock_risk
alsTrue
als het artikelseasonal
is en decurrent_stock
dehigh_stock_threshold
overschrijdt. - Definieer een andere booleaanse variabele
discount_eligible
alsTrue
als het artikelnot
selling_well
is ennot
alon_sale
is. - Maak een booleaanse variabele
make_discount
dieTrue
is als ofweloverstock_risk
ofdiscount_eligible
True
is.
Uitvoervereisten
- Print of het artikel in de korting moet:
Should the item be discounted? <make_discount>
.
Oplossing
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
seasonal = True
on_sale = False
selling_well = False
current_stock = 150
high_stock_threshold = 100
# Step 1: Combine conditions to determine overstock risk and discount eligibility
overstock_risk = seasonal and current_stock > high_stock_threshold
# Step 2: Ensure that the item is eligible for a discount by checking that it is not selling well and not already on sale
discount_eligible = not selling_well and not on_sale
# Step 3: If either boolean variable is `True`, the item should be discounted
make_discount = overstock_risk or discount_eligible
# Step 4: Print the results using the appropriate variable
print("Should the item be discounted?", make_discount)
Was alles duidelijk?
Bedankt voor je feedback!
Sectie 3. Hoofdstuk 3
9
1
2
3
4
5
seasonal = True
on_sale = False
selling_well = False
current_stock = 150
high_stock_threshold = 100
Vraag AI
Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.