Logic Gate Control Room
TRUE, FALSE, AND, OR, NOT
Your mission
The air conditioner and the fire alarm are waiting for your decisions. Flip the sensors and watch AND, OR and NOT gates light up, fill in their truth tables, build compound conditions, prove De Morgan's laws, then run a program that puts loops, selection and Boolean logic together.
Explore
Move the temperature, flip the sensors, and try every combination on each circuit.
temperature > 28False
print("AC OFF")print("NO ALERT")not room_occupiedWelcome to the control room. Programs make decisions with Boolean expressions: questions whose answer is either TRUE or FALSE. Flip the sensors and watch the gates decide. Every combination you try ticks a row in the truth table.
0 of 6 discoveries made
Experiment
Build compound conditions, test De Morgan's laws, and run the lecture's air-conditioner program.
Control-room experiments
Try each one. They tick themselves off.
0 of 6 experiments done
Challenge
Six decisions: evaluate conditions, turn rules into code, fill in a truth table and predict a program's output.
Control-room rules
- A and B: TRUE only when both are TRUE
- A or B: TRUE when at least one is TRUE
- not A: reverses TRUE and FALSE
- not (A and B) = (not A) or (not B)
- not (A or B) = (not A) and (not B)
=assigns,==compares
Make all 6 decisions to finish this stage.
Understand
Here is what the control room was showing you, in the words you need for the exam.
Boolean logic: TRUE and FALSE
Boolean expressions evaluate to either TRUE or FALSE. Programs use them to decide what actions to perform, and conditions can be combined to express more complex requirements. The three fundamental logical operators are AND, OR and NOT.
Comparison operators
| Operator | Meaning | Example |
|---|---|---|
> | Greater than | 10 > 5 → True |
< | Less than | 10 < 5 → False |
>= | Greater than or equal | 5 >= 5 → True |
<= | Less than or equal | 4 <= 3 → False |
== | Equal to | 8 == 8 → True |
!= | Not equal to | 8 != 5 → True |
Important: Python uses = for assignment (score = 10) and == for equality comparison (score == 10).
AND: both must be TRUE
| A | B | A AND B |
|---|---|---|
| True | True | True |
| True | False | False |
| False | True | False |
| False | False | False |
Useful when a program needs several requirements to be satisfied: temperature > 28 and occupied.
OR: at least one is TRUE
| A | B | A OR B |
|---|---|---|
| True | True | True |
| True | False | True |
| False | True | True |
| False | False | False |
Useful when a program should act if any required condition is met: smoke_detected or excessive_heat.
NOT and compound conditions
The NOT operator inverts a Boolean value: TRUE becomes FALSE, and FALSE becomes TRUE. not room_occupied is TRUE when the room is not occupied.
Boolean operators can be combined, and parentheses make the intended grouping clearer: not (smoke_detected or high_temperature) is TRUE when neither smoke nor high temperature is detected.
De Morgan's laws
Two expressions are equivalent when they produce the same result for every combination of inputs.
- First law: ¬(A ∧ B) = ¬A ∨ ¬B: the negation of (A AND B) is (NOT A) OR (NOT B).
- Second law: ¬(A ∨ B) = ¬A ∧ ¬B: the negation of (A OR B) is (NOT A) AND (NOT B).
Example: the AC runs when room_hot and room_occupied, so it stays off when not room_hot or not room_occupied.
Putting it all together
Output: AC OFF, AC ON, AC ON. A high-level language expresses the instructions, the Python runtime executes them, a for loop repeats for three temperatures, an if/else selection chooses the output, and Boolean logic (AND) requires both conditions to be TRUE.
Words to know
- Boolean expression
- An expression that evaluates to either TRUE or FALSE.
- Comparison operator
- >, <, >=, <=, == or !=: compares two values and gives TRUE or FALSE.
- AND
- TRUE only when both conditions are TRUE.
- OR
- TRUE when at least one condition is TRUE.
- NOT
- Reverses a Boolean value.
- Truth table
- Lists the result of an expression for every combination of inputs.
- Compound condition
- Conditions combined with AND, OR and NOT.
- De Morgan's laws
- Show how NOT changes AND into OR, and OR into AND.
Exam tip
To evaluate a compound condition, work from the inside out: first each comparison (29 > 28 → True), then anything in brackets, then NOT, then AND/OR. To prove two expressions equivalent, write a truth table with every combination (4 rows for two inputs) and show the two result columns are identical. And watch the boundary: 28 > 28 is False.