🎯 What you will learn
- Compare values with ==, > and <
- Use if and else
- Add more choices with elif
👋 Let’s get started!
Programs get smart when they can make decisions 🧠. Is the password right? Did you win? Let’s teach Python to choose!
🪜 Step by step
1. ⚖️ Comparing
== checks if things are equal. > means bigger, < means smaller.
print(5 > 3)
print(2 == 4)
2. 🔀 if / else
If the question is True, do the first part. Otherwise do the else part.
age = 9
if age >= 8:
print("You can ride! 🎢")
else:
print("Next year! 🙂")
3. 🛣️ elif
elif adds more paths in between.
score = 75
if score >= 90:
print("Gold 🥇")
elif score >= 70:
print("Silver 🥈")
else:
print("Bronze 🥉")
🧪 Try it!
Change the code and press ▶ Run to see what happens. You can’t break anything!
Secret door
password = input("Say the password: ")
if password == "banana":
print("The door opens! 🚪✨")
else:
print("Wrong password! 🔒")Weather helper
temp = 30
if temp > 25:
print("Wear shorts 🩳")
else:
print("Wear a jacket 🧥")📖 Key words
Tap a card to flip it over!
- if
- Do this only if it’s true ❓
- else
- Otherwise, do this ➡️
- ==
- Checks if two things are equal ⚖️
🏆 Challenge
Set number = 7. If it is bigger than 5 print “big”, otherwise print “small”.
Challenge
number = 7
Knowledge Check Quiz
- What prints?
- Which checks if x equals 10?
- What does elif add?