"Python Conditional Logic – If, Elif, Else & Boolean Values"
In Python, the if statement allows us to run or skip a block of code based on a specified condition. raining = True #Assignment Operator if raining == True: #Comparison Operator print("Take Umbrella") else:
In Python, the if statement allows us to run or skip a block of code based on a specified condition.
raining = True #Assignment Operator
if raining == True: #Comparison Operator
print("Take Umbrella")
else:
print("No need for Umbrella")
Output : Take Umbrella
user_age = 18
if user_age >= 18:
print("permission granted")
else:
print("No Permission")
output: permission granted
mark = 89
if mark >= 90:
print("A+ Grade")
elif mark >= 75:
print("A Grade")
elif mark >= 60:
print("B Grade")
elif mark >= 35:
print("C Grade")
else:
print("Re Appear")
output : A Grade
physical_test = True # Variable assignment
written_test = True # Variable assignment
if physical_test == True:
if written_test == True: # Both variables contain True.
print("Send them appointment order")
else:
print("Physical Test Pass, Written Test - Fail")
else:
print("Physical Test - Not Clear")
output : Send them appointment order
quarter_finals = "LOST"
if quarter_finals == "WIN":
print("IND Vs SA")
ind = 270
sa = 267
if ind > sa:
print("India enters Semi finals")
else:
print("SA Enters Semi Finals")
a = False
b = True
if a and b: # False and True → False
if False:
print("Hi")
elif a or b:# 0 or 1
print("Hello")
else:
print("Vanakkam")
output : Vanakkam
0 * 1 = 0
0 + 1 = 1
name = "Subash" #True
name2 = "" #0 --> False
name3 = " " #Space
if name3:
print("Welcome")
else:
print("Vanakkam")
output : if name = True ("welcome")
: if name2 = False ("Vanakkam")
: if name3 = True ("welcome") # space
no1, no2, no3 = 5, 10, 15
if no1 < no2 and no2 < no3 or no3 == 100:
print("Hi")
elif no1 > no2 or no2 > no3:
print("Hello")
else:
print("Vanakkam")
output : Hi
name1 = 'prem'
name2 = 'Prem'
if name1 == name2:
print("Hi Prem")
else:
print("Hello Prem")
output: Hello Prem
result = True #Non-zero
if result == 1:
print("One")
elif result == True:
print("True")
else:
print("Hello")
output : One
Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.