Learn it
A Boolean value is either True or False. We combine them with:
and: True only if both are True.or: True if at least one is True.not: flips True and False.
| A | B | A and B | A or B |
|---|---|---|---|
| True | True | True | True |
| True | False | False | True |
| False | True | False | True |
| False | False | False | False |
π§° Tool: any free online Python editor such as Online Python or Trinket, or install Python from python.org and use IDLE.
Code examples
Python
has_ticket = True
is_tall_enough = False
print(has_ticket and is_tall_enough) # False
print(has_ticket or is_tall_enough) # True
print(not is_tall_enough) # True
age = 11
print(age >= 9 and age <= 12) # True
Text after # is a comment: Python ignores it.
Project: Theme park rules
- Write rules for a ride using and/or (age, height, with an adult).
- Turn them into Python with variables.
- Test 4 different visitors.
Challenge: Write a truth table for not (A and B).