Lesson 11 of 30
Lesson 11 ? True or False
Title: Make yes-or-no ideas with booleans
Description: Learn True, False, and, or, and not with easy examples about games, pets, and school bags.
Why it matters for kids: A program often needs to know if something is true before it chooses what to do next.
1. First booleans
is_sunny = True
is_raining = False
print(is_sunny)
print(is_raining)True and False are special Python values. They are not strings.
2. Comparisons make booleans
score = 12
print(score > 10)
print(score == 12)
print(score < 5)3. Use and
has_key = True
knows_password = True
if has_key and knows_password:
print("Open the treasure room.")
else:
print("Keep looking for clues.")4. Use or
has_cookie = False
has_cake = True
if has_cookie or has_cake:
print("Snack time!")
else:
print("Find a snack.")5. Easy examples
is_weekend = True
if is_weekend:
print("Time to play and code.")battery = 80
is_robot_ready = battery > 50
print("Robot ready:", is_robot_ready)is_door_closed = True
if not is_door_closed:
print("Walk in.")
else:
print("Knock first.")6. Mini challenge
Click each example to open it.
Example 1
Create is_sunny = True.
Example 2
Create is_raining = False.
Example 3
Print both boolean values.
Example 4
Check if score > 5.
Example 5
Check if age == 9.
Example 6
Use and with two true values.
Example 7
Use or with one true value.
Example 8
Use not with a closed door.
Example 9
Make has_key for a treasure room.
Example 10
Make a ready/not ready robot check.