What Are Conditions?

STEP 1 — What Are Conditions? (a.k.a. Teaching Your Game to Make Decisions Like a Real Human… Sort Of)

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%.

Try changing the health value and click Run

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.

Modify and Run

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!"

Modify and Run

Boom.
Your game now knows when you're rich enough to shop.