In the last lesson, you taught Python how to ask a question.
“If this is true, do something.”
That was a big step.
But there’s still a tiny problem.
When the answer is false, Python just… says nothing.
No message.
No reaction.
No explanation.
Sometimes that’s fine.
But most of the time, silence is confusing.
That’s where else comes in.
The Problem with Silence
Let’s look at this again:
age = int(input("How old are you? "))
if age >= 18:
print("You are allowed in.")
If the user types 20, they get a message.
If they type 15, the program ends quietly.
Beginners often think:
“Did my code break?”
Nope.
Python just didn’t have instructions for what to do otherwise.
So let’s give it some.
Enter: else
else literally means:
“If the condition above is false, do this instead.”
Here’s the same example, upgraded:
age = int(input("How old are you? "))
if age >= 18:
print("You are allowed in.")
else:
print("Sorry, you're not old enough.")
Now Python always responds.
One path runs if the condition is true.
The other path runs if it’s false.
Exactly one of them will run.
Never both.
How Python Chooses
Python reads this as:
Check the condition
If it’s true → run the
ifblockOtherwise → run the
elseblockThen continue with the program
There’s no guessing.
No randomness.
Just a clean decision.
Think of it like a fork in the road:
Left path: condition is true
Right path: condition is false
Python picks one and keeps walking.
Indentation Still Matters (A Lot)
Just like with if, indentation tells Python what belongs where.
if condition:
this_runs_if_true
else:
this_runs_if_false
Both blocks must line up properly.
If the indentation is wrong, Python won’t “try its best.”
It will stop and complain.
That’s a good thing.
It keeps your logic clear and predictable.
A Friendly Example
name = input("What's your name? ")
if name == "Alex":
print("Hey Alex! Welcome back.")
else:
print("Nice to meet you!")
Only Alex gets the special greeting.
Everyone else still gets something friendly.
No awkward silence.
You Can Only Have One else
An if statement can have:
One
ifOptional
else
That’s it.
else always belongs to the closest if above it.
Python reads code top to bottom, so placement matters.
Thinking in Plain English (Again)
Before writing code, say it out loud:
If the password is correct, allow access
Otherwise, deny access
If the number is even, say “Even”
Otherwise, say “Odd”
If you can say it clearly, the code almost writes itself.
What You’ve Learned
You now know how to:
Handle both outcomes of a condition
Prevent silent programs
Give Python a clear backup plan
Build simple two-path logic
This is the foundation of real decision-making.
Mini Quiz
Try these:
What does
elsemean in plain English?Will both
ifandelseever run?What happens if the condition is false and there’s no
else?Why is indentation important in
if / elseblocks?What will this code print?
number = 3
if number > 5:
print("Big")
else:
print("Small")