To follow up on the introduction to Logic Gates post, this assignment is intended to help students practice using functions and logic statements.
- Write a set of function that act as logic gates. That is, they take in one or two inputs, and gives a single true or false output based on the truth tables. Write functions for all 8 logic gates in the link. An example python program with a function for an AND gate (the function is named myAND) is given in the glowscript link below.
- Write a function that uses these functions to simulate an half-adder circuit. Create a truth table for the input and output.
- Write a function that uses the gate functions to simulate a full-adder circuit. Create a truth table for the input and output.
Here’s a program with an example function for an AND gate (called myAND), and a simple program to test it.
The half-adder circuit is shown below.
The full adder circuit: