Card 4: Booleans

Module 2: Making Decisions

1 The Hook

A Boolean is like a Light Switch.

It can only be in one of two states:

  • True (On)
  • False (Off)

2 Worked Example

We can store True/False directly, or ask a question to get one.

is_sunny = True # Setting it directly
is_cold = False # Note capital T and F
game_over = 10 > 5 # Asking: "Is 10 bigger than 5?" -> True

PREDICT

What will this code print?

score = 100
print(score > 200)

Interactive Editor

> _
BRONZE (MODIFY)

🥉 Make it True

1. Copy the code.
2. Change the Operator (>) to make the answer True.
(Hint: Use < for "less than").

# Is 50 bigger than 100? No.
print(50 > 100)
> _
SILVER (FIX)

🥈 Capital City

This code has 2 errors.
1. Python case-sensitivity (true vs True).
2. Assignment order (variable on left).

> _
GOLD (MAKE)

🥇 Age Checker

1. Ask user for their age (remember int()!).
2. Create a variable old_enough that checks if age >= 18.
3. Print old_enough.

> _