๐Ÿ PyQuest๐Ÿค” Making Decisions ยท ๐ŸŒฆ๏ธ if ... else: Plan B
โญ 0 XP๐Ÿ Python is waking upโ€ฆ

if ... else: Plan B ๐ŸŒฆ๏ธ

if does something when the answer is True. But what about when it's False? That's where else comes in โ€” it's your backup plan.

age = 8

if age >= 13:
    print("Welcome to the teen zone!")
else:
    print("Come back in a few years ๐Ÿ˜„")

Exactly one of those two messages prints. Never both, never neither. Python picks a path and takes it.

(>= means "greater than or equal to", by the way.)

Booleans work great with if all by themselves:

raining = True

if raining:
    print("Umbrella time โ˜”")

if raining: is just a shorter way of saying if raining == True:.

Your mission

  1. Make a variable raining and set it to True or False (no quotes!)
  2. If it's raining, print a rainy-day message
  3. Use else to print a totally different sunny-day message

Your code

Press โ–ถ Run to see what your code does!