Introduction
Conditional statements allow you to execute code based on certain conditions.
If Statement
age = 18
if age >= 18:
print("Adult")
elif age >= 13:
print("Teenager")
else:
print("Child")
Ternary Operator
status = "Adult" if age >= 18 else "Minor"
Multiple Conditions
score = 85
attendance = 90
if score >= 90 and attendance >= 80:
print("Excellent")
elif score >= 70 or attendance >= 70:
print("Good")
else:
print("Needs improvement")
Practice Problems
- Grade calculator (A, B, C, D, F)
- Leap year checker
- BMI calculator with health categories
- Traffic light simulator
- Password strength validator