ON OR OFF?
Computers only understand 2 states. We represent this by using a 1 and a 0. Inside the CPU of a computer are millions of individual switches called transistors.
A transistor is a basic electrical component that alters the flow of electrical current. A computer may seem clever but in fact all it does is carry out calculations (computes) and perform logic operations. These happen in the Arithmetic and Logic Unit (ALU) of the central processing unit. |
Boolean Logic in programming
Logic gates - AND, OR, NOT
Logic gates are the electrical circuits that make up all circuits inside a computing device.
AND gate
A and B are inputs. Q is used to represent an output.
In a circuit with an AND gate, both inputs need to be on (both set to 1) in order to get an output.
In a circuit with an AND gate, both inputs need to be on (both set to 1) in order to get an output.
Truth Table for AND gate.
Truth tables are used to model the outcomes of a gate. Remember that A and B are inputs and Q is the output. With an AND gate there will only be an output if both inputs are on (1). You can also think of this as condition A and condition B both being TRUE.
OR gate
A and B are inputs. Q is used to represent an output.
In a circuit with an OR gate, either input need to be on (set to 1) in order to get an output.
In a circuit with an OR gate, either input need to be on (set to 1) in order to get an output.
Truth Table for OR gate.
Truth tables are used to model the outcomes of a gate. Remember that A and B are inputs and Q is the output. With an OR gate there will be an output if either input is on (1). You can also think of this as either condition A or condition B being TRUE.
NOT gate
A is an input. Q is used to represent an output.
In a circuit with a NOT gate, the output occurs when the input is switched OFF (0). You can also think of this as an output happening only if the condition is FALSE.
In a circuit with a NOT gate, the output occurs when the input is switched OFF (0). You can also think of this as an output happening only if the condition is FALSE.
Truth Table for NOT gate.
Logic Gates Task
|
Guess Who?
In the game of Guess Who? the aim is to identify the person by asking only yes/no questions. Yes or no indicate 2 states so when playing this game we are applying Boolean logic. Click on the button to play a couple of rounds of GUESS WHO? to practice your logical thinking. -->
|
In your book, put the date and the title: Guess Who? - Boolean Logic
Use the Python code below to work out the answers. This will also show you how Boolean logic is programmed. What you need to remember:
|
Work out the answers FROM THE PEOPLE SHOWN ABOVE (use your book to eliminate people as you go and record the final answer to each round in your book.)
Round 1
Round 2
Round 3
Round 4
Your turn
Pick a character and write out Python to identify them. Test your code on a friend.
Email your Python code to your teacher.
Email your Python code to your teacher.
Real-world examples of Boolean logic
AND gate examplesIn our smart house, we have an automatic watering system. This work by having a moisture sensor in the ground and a clock. The sprinkler will be activated if the moisture content falls below a set level AND it is night-time.
To launch a nuclear attack TWO buttons must be pressed. The buttons are not in the same location so it is not possible for just one person to launch the attach. Button A AND button B must be pressed. |
OR gate examples
In our smart house, we have a biometric entry system. We can enter EITHER by using our fingerprint or by using iris (eye) scanning.
his is useful if you have your hands full and cannot use the fingerprint scanner. But you don't need to use both to gain entry. In many houses there is a light switch at the top of the stairs, and another at the bottom. Both switches control the same light bulb. But only one switch needs to be flicked in order to turn on the light. |
Not gate examples
Logic Gates in CarsUse logic.ly/demo to create circuits for the windscreen wipers and the inside lights. Details below.
Screenshot your circuits to a Powerpoint and share it with your teacher. |
Automatic windscreen wipers system
Your task is a to design a logic gates circuit for automatic windscreen wipers system that use the following rules:
Inside light system The interior light is used to light up the inside of the car. The light is located on the ceiling of the car and can be manually turned on and off using a light switch located next to the light. Most cars are also equipped with sensors on each door. These sensors are on (1) when the door is open and off when the door is closed (0). Each door has its own sensor, including the driver door, the passenger door and the door to access the boot. Your task is a to design a logic gates circuit for the inside light system that will apply the following rules:
This circuit needs 2 or gates as shown. Can you join them up correctly to turn the light according to the rules set? |
Practice your coding
Task 1 - add to existing code
Copy and paste the code into a Thonny file - save as 'weather'
The same way the code randomly finds out if today will be sunny or rainy, add some code to find out whether it will be icy and whether it will be snowy.
If the weather is icy then display a message saying: “Be careful not to fall over today”
If the weather is either icy or snowy then display a message saying: “Put your gloves on, it’s going to be cold today.”
Choose your own statements for the other options. Such as sunny AND snowy.
If the weather is icy then display a message saying: “Be careful not to fall over today”
If the weather is either icy or snowy then display a message saying: “Put your gloves on, it’s going to be cold today.”
Choose your own statements for the other options. Such as sunny AND snowy.
Task 2
Add a criteria to find out if it will be windy or not.If the weather is both sunny and windy write a message saying: “It’s a good time to go sailing!”
If the weather is sunny but not windy write a message saying: “A perfect day to go to the beach!”
Add your own statements for the other possible combinations - eg. not sunny and not windy, not sunny but windy.
If the weather is sunny but not windy write a message saying: “A perfect day to go to the beach!”
Add your own statements for the other possible combinations - eg. not sunny and not windy, not sunny but windy.
Task 3
Rio the parrot gets very talkative if:
Copy and paste the code below into a Thonny file - save as 'Rio'
Complete the code to tell the zoo keeper whether Rio will be quiet or noisy.
- It is early in the morning (between 5am and 10am).
- It is sunny outside.
Copy and paste the code below into a Thonny file - save as 'Rio'
Complete the code to tell the zoo keeper whether Rio will be quiet or noisy.
Task 4
Copy and paste the code into a Thonny file - save as 'Leon'
Complete the program to tell the Zoo keeper if Leon the lion will be asleep, hungry or happy!
Leo will be:
Complete the program to tell the Zoo keeper if Leon the lion will be asleep, hungry or happy!
Leo will be:
- Sleepy if his sleeping time has not reached 18 hours
- Hungry if his sleeping time is over 18 hours and he has not been fed.
- Happy if his sleeping time is over 18 hours and he has been fed.
Task 5
During the summer the penguins love to go for a swim when the water temperature in the pool is at least two degrees cooler than the outside temperature.
Split the screen and copy below into a Thonny file - save as 'penguins'
Complete the code to tell the zoo keeper where he can expect to find the penguins: either sunbathing outside or swimming in the pool.
Split the screen and copy below into a Thonny file - save as 'penguins'
Complete the code to tell the zoo keeper where he can expect to find the penguins: either sunbathing outside or swimming in the pool.
Recap
Quick revise with Quizlet
|