Every condition in a program is either true or false. Logic words — AND, OR and NOT — combine conditions: AND needs both parts true, OR needs at least one, and NOT flips true to false.
Apa yang akan dipelajari anak anda
- Decide whether simple statements are true or false
- Use AND: both parts must be true
- Use OR: at least one part must be true
- Use NOT to reverse a condition
AND, OR, NOT
“The number is more than 2 AND less than 6” is true for 3, 4 and 5 only. “Less than 2 OR more than 6” is true for 0, 1, 7, 8 and up. A game might give a bonus only if score > 100 AND lives > 0 — miss either and there’s no bonus.
Contoh soalan
Berikut ialah beberapa soalan seperti dalam misi pertama. Bolehkah anda menjawabnya?
1. In coding, a condition is always either…
- big or small
- true or false
- red or blue
- up or down
Tunjuk jawapan
Jawapan: true or false. Conditions are checked as true or false.
2. “It is raining AND it is windy” is true when…
- only one part is true
- neither part is true
- always
- both parts are true
Tunjuk jawapan
Jawapan: both parts are true. AND needs both parts to be true.
3. What does NOT do to “true”?
- Makes it bigger
- Deletes it
- Keeps it true
- Turns it into false
Tunjuk jawapan
Jawapan: Turns it into false. NOT flips true to false, and false to true.
Tip untuk orang dewasa
- Play “Stand up if you have a pet AND you like apples”, then try OR.
- Ask true-or-false questions at dinner: “Broccoli is blue OR carrots are orange.”