capypad
0 day streak
python / beginner
Snippet

Multi-Condition If Statements

Using elif allows you to check multiple distinct conditions in order, stopping as soon as one evaluates to True.

snippet.py
python
1
2
3
4
5
6
7
score = 85
if score >= 90:
print("Grade: A")
elif score >= 80:
print("Grade: B")
else:
print("Grade: C")
Breakdown
1
if score >= 90:
Check the first condition for a high score.
2
elif score >= 80:
Check a secondary condition only if the first one was false.
3
else:
Provide a default action if none of the previous conditions were met.