Python 3 Tutorial · Chapter 11 of 22
Python Nested If
Combine conditions with nested decisions.
A nested if runs another check only when the outer condition is already true.
Keep nesting shallow so classrooms can still read the logic.
Nested if sample
Try it Yourself »
score = int(input("Enter score: "))
attendance = int(input("Enter attendance percentage: "))
if score >= 75:
if attendance >= 80:
print("Passed and qualified.")
else:
print("Passed, but attendance needs review.")
else:
if score >= 60:
print("Needs remedial activity.")
else:
print("Failed.")
Classroom Tips
- elif can flatten some nested checks.
- Test both outer and inner branches.