Can we play outside? AND, OR and NOT
Tell the program whether it is raining, whether your homework is done and whether it is a holiday, and watch it work out each part of the rule with NOT, AND and OR before it decides whether you can play outside.
Core concept
NOT turns true into false; AND is true only when both parts are true; OR is true when at least one part is true, so a long condition can be worked out one part at a time
Topic: Decision making
Many decisions depend on more than one thing. “You can play outside if it is not raining and your homework is done, or if it is a holiday.” A program joins condition: A question with a yes or no answer that decides what the program does next. All key words with three small words. NOT flips a condition: if raining is true, NOT raining is false. AND is true only when both sides are true. OR is true when at least one side is true. In this lab, 1 means true (yes) and 0 means false (no). The program works out the rule in parts: first dry = NOT raining, then ready = dry AND homework, and last ready OR holiday.
What you will learn
- Work out NOT, AND and OR for true (1) and false (0).
- Break a long condition into smaller parts.
- Predict the decision for any set of inputs.
- Choose the condition that matches a rule written in words.
Before you start
- Know if / else and what a condition is.
Materials
- A notebook to draw a small truth table
Equipment
- None
Procedure
- Run the program on a dry day with the homework done.
- Make it rain and run it again.
- Make it a holiday, even in the rain, and run it.
- Answer the practice challenges.