Python Learning – Day 4: Conditional Statements (if, else, elif)
Introduction
Welcome to Day 4 of my Python learning journey.
In this lesson, I learned how Python makes decisions using conditional statements such as if, else, and elif.
Conditional statements are extremely important in programming because real-life applications constantly make decisions based on conditions.
📚 Topics Covered in Day 4
In this lesson, I learned:
- What are conditional statements
- How
ifworks in Python - How
if-elsecontrols program flow - How
elifhandles multiple conditions - Using conditions with user input
🔀 What Are Conditional Statements?
Conditional statements allow a program to execute different code blocks based on conditions.
In simple words:
If a condition is true → do something
Else → do something else
🧠 Simple if Example
age = 20
if age >= 18:
print("You can vote")
This code checks whether a person is eligible to vote.
🔄 if – else Example
age = 16
if age >= 18:
print("You can vote")
else:
print("You cannot vote")
Here, Python makes a decision based on the value of age.
🧮 Real-Life Example: Pass or Fail
marks = 35
if marks >= 40:
print("Pass")
else:
print("Fail")
This logic is commonly used in school result systems.
➕ Multiple Conditions Using elif
marks = 75
if marks >= 90:
print("Excellent")
elif marks >= 60:
print("Good")
elif marks >= 40:
print("Pass")
else:
print("Fail")
Python checks the conditions from top to bottom and executes the first true condition.
🧾 Real-Life Program: Student Result System
name = input("Enter your name: ")
marks = int(input("Enter your marks: "))
if marks >= 90:
print(f"{name}, your result is: Excellent")
elif marks >= 60:
print(f"{name}, your result is: Good")
elif marks >= 40:
print(f"{name}, your result is: Pass")
else:
print(f"{name}, your result is: Fail")
This program behaves like a real-world student result evaluation system.
🌍 Why Conditional Statements Are Important
Conditional statements are used in:
- Login systems
- Eligibility checks
- Exam result processing
- Banking and finance applications
- Decision-based automation
Without conditional logic, programs would not be able to make decisions.
✅ What I Learned Today
- How to use
if,else, andelif - How Python makes decisions
- How to apply logic to real-life problems
- How to create interactive decision-based programs
This lesson helped me understand the foundation of decision-making in Python.
🔜 Next Lesson (Day 5)
In Day 5, I will learn about:
- Loops in Python
- Repeating tasks automatically
- Real-life loop examples
📢 Final Note
This Python learning series is written for beginners.
Anyone who wants to learn Python step by step can follow these posts.
Thank you for reading 🚀