Lesson 3 – Making Decisions with
IF Statements
Today, you’ll learn how to make your programs think for themselves. Python
can choose what to do based on conditions — just like how we make decisions every
day.
1. Why Do Computers Need Decisions?
Imagine a vending machine :
• If you insert enough money, it gives you a drink.
• If not, it says “Not enough money.”
That’s how if statements work — they allow the computer to make decisions
based on information.
In Python:
if condition_is_true:
do_this
else:
do_that
2. The IF Statement
Example 1 – Checking Age
age = 18
if age >= 18:
print("You can vote ")
What happens? Python checks if age >= 18. If that’s true, it prints the message.
If it’s false, it skips it.
1
Think!
Try changing age = 15. What happens? What if you use > instead of >=?
3. The IF–ELSE Statement
Sometimes we need to do one thing when the answer is YES and another when it’s NO.
Example 2 – Movie Access
age = int(input("How old are you? "))
if age >= 12:
print("You can watch the movie ")
else:
print("Sorry, you are too young ")
Example Output:
How old are you? 10
Sorry, you are too young
Notice: The code under each block must be indented (moved right with 4 spaces
or one tab).
—
4. The IF–ELIF–ELSE Ladder
Multiple Choices
When there are many possibilities, use elif (else if). Python checks conditions
one by one — when it finds one that’s true, it stops.
2
Example 3 – Grading System
score = int(input("Enter your score: "))
if score >= 90:
print("Excellent! ")
elif score >= 75:
print("Great job ")
elif score >= 50:
print("You passed ")
else:
print("Keep studying ")
Discuss: What happens if you enter 82? What if you enter 45?
—
5. Comparison Operators
Python uses these symbols to compare values:
Operator Meaning Example
== Equal to a == b
!= Not equal to a != b
> Greater than a > b
< Less than a < b
>= Greater or equal a >= b
<= Less or equal a <= b
6. Logical Operators
You can join two or more conditions together:
Operator Meaning Example
and True if both are true x > 0 and x < 10
or True if at least one is true x == 5 or y == 5
not Inverts True/False not raining
3
Example 4 – Going Out?
is_raining = True
has_umbrella = False
if not is_raining or has_umbrella:
print("You can go outside ")
else:
print("Better stay home ")
7. Practice Zone
Challenge 1 – Odd or Even
Ask the user for a number and check if it’s even or odd. Hint: use the modulus
operator %.
number = int(input("Enter a number: "))
if number % 2 == 0:
print("Even!")
else:
print("Odd!")
Challenge 2 – Password Check
Create a program that asks for a password. If it matches your secret password,
print “Access granted ”. Otherwise, print “Wrong password ”.
8. Common Mistakes to Avoid
• Forgetting to indent lines after if, elif, or else.
• Using = instead of == when comparing.
• Writing conditions like if x = 5: instead of if x == 5:.
4
9. Mini Project – Adventure Game
Create Your Own Adventure!
Let’s use everything we learned to make a small interactive story.
print("Welcome to the Mysterious Forest ")
print("You see two paths ahead: left or right.")
choice = input("Which way do you go? (left/right): ")
if choice == "left":
print("You find a treasure chest full of gold! ")
elif choice == "right":
print("Oh no! You meet a hungry bear and run away!")
else:
print("You stand still... maybe next time you’ll decide faster!")
Try to add:
• More choices (add an elif for “back” or “forward”).
• Nested conditions (inside the first if).
• Sound effects like “Wow!” or emojis to make it fun.
10. Recap
• Use if, elif, and else to control decisions.
• Always indent code under a condition.
• Combine conditions with and, or, not.
• Think logically — your computer only understands True or False.
”Programming is like teaching your computer how to think — one question at a time!”