if age >= 18:
print("Eligible")
❌ Incorrect Indentation
if age >= 18:
print("Eligible")
Python requires proper indentation.
Correct:
if age >= 18:
print("Eligible")
🔹 11. Real-World Data Science Example
prediction = 0.82
if prediction >= 0.5:
print("Spam Email")
else:
print("Not Spam")
Many Machine Learning classification models use similar logic to convert prediction probabilities into categories.
🎯 Practice Questions
1. Check whether a number is positive or negative.
2. Check whether a person is eligible to vote.
3. Create a grading system using "if...elif...else".
4. Check whether a number is even or odd.
5. Determine the largest of three numbers.
🎯 Key Takeaways
✅ Use "if" to execute code when a condition is True.
✅ Use "else" to execute code when the condition is False.
✅ Use "elif" to check multiple conditions.
✅ Nested "if" statements allow more complex decision-making.
✅ Logical operators (and, or, not) help combine conditions.
✅ The ternary operator provides a concise way to write simple "if...else" statements.
Conditional statements are the foundation of decision-making in Python and are widely used in automation, data analysis, machine learning, and AI applications.
Double Tap ❤️ For Part-5