Data Science · मराठी आवृत्ती · Python basics
P5.4 Python and, or, not: Conditions एकत्र करा
हे का शिकायचं?
खरे नियम दोन-तीन गोष्टींवर अवलंबून असतात: amount जास्त आणि member असेल तर free delivery.
हे काय आहे?
and म्हणजे दोन्ही खरे हवेत, or म्हणजे एक खरं पुरे, not उत्तर उलटं करतो.
कसं करायचं?
Step 1. प्रत्येक condition वेगळी लिहा.
Step 2. and/or ने जोडा.
Step 3. गोंधळ टाळायला कंस वापरा.
उदाहरणं: copy करा आणि चालवा
उदाहरण A: Free delivery नियम
हा code चालवा:
is_member = True
total = 42
if is_member and total > 30:
print("Free delivery")
else:
print("Delivery fee £3.99")
तुम्हाला दिसणारा output:
Free delivery
याचा अर्थ: and मुळे दोन्ही conditions खऱ्या असतानाच free delivery मिळाली.
उदाहरण B: Weekend किंवा सुट्टी
हा code चालवा:
day = "Sunday"
is_holiday = False
if day in ("Saturday", "Sunday") or is_holiday:
print("Extra staff needed")
तुम्हाला दिसणारा output:
Extra staff needed
याचा अर्थ: or मुळे एकही condition खरी असली तरी True आलं.
उदाहरण C: not वापरणं
हा code चालवा:
is_paid = False
if not is_paid:
print("Send payment reminder")
तुम्हाला दिसणारा output:
Send payment reminder
याचा अर्थ: not ने True चं False आणि False चं True केलं.