Hey coder buddy! 👋 Welcome back to Day 5 of your Python journey. So far, you’ve explored variables, data types, and even tackled operators. High five!
Today, we’re diving into something super powerful (and kinda magical!) Python if else statement 🧙♂️ This is what gives your code decision-making superpowers. Whether you’re building a game, a website, or automating tasks, understanding if else in Python will be a total game changer. So grab your chai ☕ (or coffee), and let’s make your code a little smarter today!
If you’re just joining the challenge, be sure to check out what Python is before diving into conditions!
The Python if else statement lets your code make decisions — just like how we do in real life.
Think of it like this:
“If it’s raining, I’ll take an umbrella. Else, I’ll wear my sunglasses.” 😎🌧️
Sounds relatable? Well, that’s the basic idea behind Python’s if, else, and elif.
Ready to learn how your code can think for itself? Let’s do it
What is the Python If Else Statement?
The Python if else statement is a way for your program to make choices based on a condition.
Example
Imagine you open the fridge.If there’s chocolate → you eat it 🍫Else you drink juice 🧃
In code, that’s basically:
if "chocolate" in fridge:
eat("chocolate")
else:
drink("juice")
You just wrote a decision-making code. Feels cool, right?
Why Learning if else is So Important
Before we jump into examples, let’s understand why this is so important for you as a beginner:
Makes your programs dynamic (reacts to different inputs)Forms the base of logic and control flow
Needed for almost every real-world app, like games, websites, chatbots, etc.
And guess what?
If you understand this concept well, loops and functions will be a walk in the park! 🌳
Python If Statement Syntax (Simple Version)
if condition:
# do something
Let’s try a super basic example:
age = 18
if age >= 18:
print("You can vote! 🗳️")
If the condition is True, the indented block under if runs.
Adding else Statement
What if the condition isn’t true? Well, here comes else to the rescue:
age = 16
if age >= 18:
print("You can vote!")
else:
print("Sorry, you're too young to vote.")
Now your code covers both situations — just like a real conversation.
Using elif (Else If)
What if there are more than two options? That’s where elif shines:
marks = 85
if marks >= 90:
print("Grade: A+")
elif marks >= 80:
print("Grade: A")
elif marks >= 70:
print("Grade: B")
else:
print("Keep working, you can do it!")
You can use as many elif as needed. But make sure the order makes sense!
Real-Life Project Idea (Mini)
Let’s create a Simple Login Checker using if else.

username = input("Enter your username: ")
password = input("Enter your password: ")
if username == "student" and password == "python123":
print("Login successful 🎉")
else:
print("Invalid credentials 😢")
See how the Python if else statement helps you check conditions and react accordingly? 🧪 Run this Code on Replit
Let’s Understand How It Works:
Step 1: Condition gets evaluated
username == “student” → Is it True or False?
password == “python123” → Is it True or False?
Step 2: If both True → runs the first block
Else → jumps to else block
That’s the flow of logic — and it’s the same idea behind more complex software too!
Nested If Else in Python
Yes, you can use if inside another if. For example:
age = 20
citizen = True
if age >= 18:
if citizen:
print("You are eligible to vote.")
else:
print("You must be a citizen to vote.")
else:
print("You are too young to vote.")
This is called a nested if else statement in Python. Pretty neat for handling complex logic!
Common Mistakes to Avoid
Let’s be real, we all mess up sometimes But here are a few things to remember:
❌ Don’t forget the colon : after if, elif, else
❌ Indentation must be consistent (use 4 spaces)
❌ Avoid overusing nested ifs — your code becomes hard to read
Pro Tips for Beginners
✔Start with real-world scenarios — weather, grades, login, etc.
✔Draw a flowchart before writing the code
✔Practice writing if-else conditions without looking at examples
And most importantly: Don’t give up!
You’re building your logic muscles Just like working out!
Practice Challenge for You
Here’s your fun task for Day 5:
Write a Python program that takes your marks as input and prints whether you passed or failed.
Pass mark = 40
If more than 90 → say “Excellent!”
Try it on your own before checking the solution 💡
What’s Next?
Up next in Day 6, we’ll unlock the magic of Python logical operators like and, or, and not the real MVPs when you want your code to make smart decisions.
Imagine checking:
If someone is above 18 and has a driving license?
Or if it’s Monday or Wednesday, show a discount?
You’ll learn how to combine multiple conditions, and we’ll even throw in some relatable mini-projects to bring it all to life Stay tuned it’s gonna be 🔥
Python is an excellent start, but why stop there? If you’re curious about how programming works at a deeper, more foundational level, check out our C Programming for Beginners guide. It’s perfect for understanding core programming concepts and building stronger logic that’ll help you in any language — including Python! 30 Day’s of C Programming for Beginners – Full Roadmap