7. Conditional Statements for Decision-Making
Learn how to make your code think and decide like a game master!
Level Up with Decision-Making Powers! 🎮
Hey coding champions! Remember those awesome string powers we learned? Now it's time to learn something even cooler - how to make your code THINK and DECIDE! Just like in games where you choose different paths on your quest, conditional statements let your code make smart choices! 🧙♂️

Today's Quest! 🎯
You'll learn how to:
- Make your code choose different paths like in an adventure game! 🗺️
- Use magical comparison operators to test conditions ✨
- Chain multiple decisions together for complex quests 🔗
- Check if items exist in your inventory using the 'in' operator 🎒
Your First Decision Spell: if Statements! 🪄
Think of if
statements like magical gates - if something is true, you get to pass through! Let's try it:
🎮 Quick Game: Try changing the player_name to different values:
- "Pi" (too short!)
- "SuperWarrior" (perfect!)
- "Zx" (too short!)
Level 2: Dragon Alert System! 🐲
Now let's check for special powers:
Cool, right? Your code just made its first decision!
Comparison Magic: Testing Conditions! ⚔️
🔍 Time to learn the magical comparison symbols::
==
: Is equal to!=
: Not equal to>
: Greater than<
: Less than>=
: Greater than or equal to<=
: Less than or equal to
🎮 Mini-Game Break: Guess the Output!
What do you think this code will print?
Take a guess before trying it out!
Secret Inventory Checker: the 'in' Operator! 🎒
Ever wanted to check if you have an item in your backpack? Here's how:
🎮 Fun Fact: The in
operator is like a magical detector that can find things in lists!
Multiple Choice Paths: elif Adventures! 🗺️
Sometimes you need more than just yes/no choices. Enter elif
- your new best friend!
🎮 Try It: Change player_class to a different value to get You charge into battle with your sword! ⚔️
!
Boss Battle: Complex Conditions! 🐉
🎮 Mini-Game: The Quest Checker!
Your mission:
-
Check if the quest is "ACTIVE"
-
Check if the player has all required items
-
Check if player meets minimum level (level 2)
🌟 Super Challenge: Create a Game Choice System!
Create conditions to check:
- If player chose "cave":
- Must have torch and hp > 50
- If player chose "mountain":
- Must have hp > 70
- If player chose "forest":
- Can enter anytime!
Check if they can enter cave, mountain, or the forest.
🎯 Debug Mission: Fix the Game Logic!
Can you spot what's wrong with these conditions? Fix them here :)
Hint: Look carefully at the type of player_power!
Hint: Check the comparison operator!
Pro Tips for Victory! 🏆
Remember:
- Always check your comparison operators
(==, !=, >, <, >=, <=)
- Pay attention to your indentation - Python is picky!
- String comparison is case-sensitive ("Sword" != "sword")
- Use 'and' to check multiple conditions that all must be True
- Use 'or' when any one condition can be True
Final Boss Challenge: Create a Complete Game Check System!
Ready for the ultimate test? Create a complete game check system!
-
Parse the player_stats (use your string powers!)
-
Check if player is ready for dragon battle:
- Level must be 5 or higher
- Health must be above 80
- Must have both Sword and Shield
- Current quest must be "DefeatDragon"
- Print appropriate messages for each condition
🎉 Congratulations!
You've learned the power of making decisions in code! Now you can:
- Make your programs think and choose paths 🤔
- Check conditions like a pro 🔍
- Create complex decision trees 🌳
- Build awesome game logic! 🎮
Ready for more coding adventures? Let's go! 🚀