if–elif–else Statement
The if–elif–else statement is used to check multiple conditions in a program.
It allows more than two choices, making decision-making easier.
The term elif means “else if”, and it helps to check conditions one by one.
When the program runs, it executes the first True condition and skips the remaining ones.
Explanation
- The program starts with if
- If the condition is False, it checks the elif condition
- It keeps checking conditions one by one
- Stops when it finds a True condition
- If none are True, the else block runs
- In the end, only one block executes

Real-Time Scenarios
- Marks grading (A, B, C, Fail)
- Traffic signal (Red, Yellow, Green)
- Weather check (Hot, Cold, Rainy)
- Age group (Child, Teen, Adult)
- Game levels (Easy, Medium, Hard)
Syntax
if condition1:
# block 1
elif condition2:
# block 2
else:
# default block
Example 1
marks = 75
if marks >= 90:
print("A Grade")
elif marks >= 75:
print("B Grade")
elif marks >= 50:
print("C Grade")
else:
print("Fail")
Output:
B Grade
Example 2
time = 14
if time < 12:
print("Morning")
elif time < 18:
print("Afternoon")
else:
print("Evening")
Output:
Afternoon
Why if–elif–else is Important
- Handles multiple conditions
- Improves decision-making logic
- Used in real-world applications
- Makes programs more efficient
Common Beginner Mistakes
- Wrong order of conditions
- Missing else block
- Incorrect indentation
- Using overlapping conditions
➤ Key Points
- Can have multiple elif blocks
- Checks conditions top to bottom
- Stops when first True condition is found
- Arrange conditions in logical order
- Avoid unnecessary elif statements
- Always include else (default case)