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.