Conditional statement
It used to control the flow of the execution of the program based on the specific condition.
if statement
It execute whether the given condition is true.
mark=75
if mark>60:
print("pass")
output:pass
elif statement
Used when you want to check another condition if the first one is false.
marks = 75
if marks >= 90:
print("Grade A")
elif marks >= 75:
print("Grade B")
elif marks >= 50:
print("Grade C")
output:Grade C
else statement
Runs when none of the above conditions are true.
marks = 30
if marks >= 90:
print("Grade A")
elif marks >= 75:
print("Grade B")
elif marks >= 50:
print("Grade C")
else:
print("Fail")
output:Fail
Top comments (0)