Make a Tiny Game
beginner25 XP

Decisions with if

Help a greenhouse and a recycling robot make choices.

Decisions with if 🤔

Smart machines make decisions. A greenhouse opens its windows when it gets too hot. A recycling robot sorts bottles from trash. They all use if.

Python
temperature = 35

if temperature > 30:
    print("Too hot - open the windows!")
else:
    print("Just right")
  • if checks something. If it's true, Python runs the indented lines under it.
  • else runs when the check is false.
  • Don't forget the colon : at the end of the if and else lines!

Comparing things

SymbolMeans
>bigger than
<smaller than
==is equal to
!=is not equal to
💡

⚠️ One = puts something in a box. Two == asks if two things are the same.

♻️ A recycling robot

Python
item = "bottle"

if item == "bottle":
    print("Recycling bin")
else:
    print("Trash bin")

🌧️ Weather warnings

Python
rain_mm = 60

if rain_mm > 50:
    print("Flood warning!")
else:
    print("Normal rain")

🌍 Fun fact

Weather apps use code full of ifs. If the wind is very strong, then send a storm alert. Your phone does this kind of thinking millions of times a day!

⌨️

Type it yourself

Don't just read it — type the example from above into the box, press Run ▶, and watch what happens. Typing it yourself is how it really sticks! Stuck? Tap Show example.

Python · Playground
Output
Press ▶ Run to see your code come to life…

Quick check

01/6
Which symbol asks "is equal to?" in an if?