What Are Conditions?
Alright coder, welcome to the unit where your game stops being a mindless robot and starts making choices.
This is the moment your code goes:
โHmmโฆ should I attack? Should I heal? Should I run away screaming?โ
Conditions are the brains of your game.
Without conditions, your game is basically a goldfish. Cute, but not very smart.
1. What Is a Condition?
A condition is a question your code asks itself:
- โIs the playerโs health low?โ
- โIs the enemy alive?โ
- โDoes the player have the key?โ
- โIs the boss angry?โ
If the answer is True, your code does one thing.
If itโs False, it does something else.
Boom.
Decision-making unlocked.
2. The Basic Structure
if condition:
# do something
This is your game saying:
โIf this thing is true, Iโll do this action.โ
Itโs like giving your code a tiny brain cell.
Just one.
But hey โ itโs progress.
3. Example: Low Health Warning
health = 20
if health < 30:
print("Warning! Health is low!")
Your game now panics appropriately.
Just like you when your phone hits 5%.
4. Example: Checking Inventory
item = "potion"
if item == "potion":
print("You drink the potion and heal!")
Your game now recognizes items like a responsible adventurer.
Practice (Your Turn!)
Mini Challenge
Create a condition that checks if coins is greater than 10.
If it is, print:
"You can buy the sword!"
Boom.
Your game now knows when you're rich enough to shop.


