Lesson 40: Logic on patrol
Two sensors, one decision
- A robot often decides from two inputs at once: "Is the floor red?" and "Is there a wall?"
- Each input is True (1) or False (0). A logic expression joins them with AND, OR, NOT or XOR.
- The output is 1 or 0. Six stops give a row of six outputs.
Words for this lesson
| Word | Meaning |
|---|---|
| input | a value that is 1 or 0, here from a sensor |
| logic expression | inputs joined with AND, OR, NOT, XOR |
| XOR | 1 when the two inputs are different |
| truth table | the output for every combination of inputs |
Truth table
| R | W | R AND NOT W | R XOR W |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 1 | 0 | 1 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 0 |
In the exam
- 0478/22/M/J/25 Q8(a): draw the XOR gate and complete its truth table. Mark scheme: A B → X is 0 0 → 0, 0 1 → 1, 1 0 → 1, 1 1 → 0.
- Logic expressions with XOR appear in many papers, for example 0478/21/M/J/25 Q7: X = (A AND B) XOR (B OR NOT C). Work out each bracket first, then the gate between them.
Kesulitan 3/5 · 200 koin + bonus kecil pada penyelesaian pertama hari ini
The robot stops at 6 places. At each one it reads two inputs: R is True if it stands on a red tile, W is True if a wall is close on its left. Write the logic for the output: X = R AND NOT W. The program adds 1 atau 0 ke out for each stop and prints it, for example Output: 100000. Each map has different tiles and walls.
Klik Jalankan untuk melihat output di sini.
Kesulitan 4/5 · 280 koin + bonus kecil pada penyelesaian pertama hari ini
Now the output is X = R XOR W: 1 when exactly one of the two inputs is 1, and 0 when both are the same. Python has no xor word for True/False, but "different" is !=.
Klik Jalankan untuk melihat output di sini.