Lesson 4 of 13

If / Else: Make Decisions! 🔀

Your code can think! It asks a question — and does different things based on the answer. Just like you do every day!

☔ Is it raining?
✅ YES
☂️ Take
umbrella!
❌ NO
😎 Wear
sunglasses!
🤔 What is If / Else?

Code Can Make Smart Decisions!

No more doing the same thing every time — your code chooses!

When I first learned about if/else, my teacher used a choose-your-own-adventure book as an example. You reach a fork in the road — turn left or right? Your code does the same thing. It checks a condition and picks a path. That’s all there is to it! 😊

📖
“You find a mysterious door. Do you open it?”
YES →
Go to page 15.
You find treasure! 💎
NO →
Go to page 23.
You walk away safely! 🚶

🌍 If / Else in Real Life

You Do This Every Day!

If/else thinking is everywhere — you just never noticed!

🌧️

Going Outside

IF it’s raining THEN bring umbrella ☂️ ELSE wear sunglasses 😎
🍕

Feeling Hungry

IF I’m hungry THEN eat a snack 🍎 ELSE keep playing 🎮
🚦

Traffic Light

IF light is green THEN walk across 🚶 ELSE wait patiently ✋
😴

Bedtime

IF it’s 10pm THEN go to sleep 💤 ELSE keep having fun 🎉

🎮 Try It Yourself!

Interactive Decision Maker!

Move the sliders — watch the if/else decide what to do!

🌤️ Weather Decision Maker

Adjust temperature and sunshine — see what your code decides!

🌡️ Temp (°C) 25°
☀️ Sunshine 7/10
🏖️ Perfect beach day! Go outside! if temp > 20 and sun > 5: “Go outside!”

✨ Types of If / Else

3 Ways to Write Decisions

Each one handles a different situation!

if

Just IF — One Decision

When you only need to check one thing. If it’s true — do it. If not — do nothing at all.

I use this when I want my game to only do something when the player scores! 🎮

score = 100

if score >= 100:
    print("🏆 You win!")
if else

IF / ELSE — Two Paths

When there are two possible outcomes. One thing happens if true — something else if false!

Like a coin toss — heads or tails. Always one of the two! 🪙

if raining == True:
    print("☂️ Take umbrella!")
else:
    print("😎 Wear sunglasses!")
if elif else

IF / ELIF / ELSE — Many Choices

When you have more than two options! Check the first, then the second, then the third…

Like a grade checker — A, B, C, or D. More than two options! 📊

if score >= 90:
    print("⭐ Amazing! A+")
elif score >= 70:
    print("👍 Good job! B")
else:
    print("💪 Keep going!")

🔍 Asking Questions in Code

6 Symbols You Need to Know

These symbols help your code ask yes/no questions!

==Equal to?age == 10
!=NOT equal?color != “red”
>Greater than?score > 50
<Less than?time < 60
>=Greater or equal?coins >= 50
<=Less or equal?health <= 0

🧠 Quick Quiz!
🎯 If / Else Quiz

4 questions · pick an answer to check!

⭐ Remember This!

🔀

IF asks a yes/no question in your code

↩️

ELSE is what happens when the answer is NO

📋

ELIF lets you check even more options

🧠

If/else makes your code smart and dynamic!