# Truth Table Generator (Using Python) The purpose of this blog post is to write a Python script that will interpret a Boolean expression and output its full Truth Table.

#### Boolean Expressions & Truth Tables

Before attempting this challenge, you should test your understanding of Boolean expressions, logic gates diagrams and truth tables by competing this online quiz:

#### Python Bitwise Operators

To implement a Python script than can interpret a Boolean expression we will the following bitwise operators:

 Bitwise Operator Example Meaning & a & b Bitwise AND | a | b Bitwise OR ^ a ^ b Bitwise XOR ~ ~a Bitwise NOT

Note that in Python, the following two bitwise operators can also be used to perform a bitwise left shift or right shift:

 Bitwise Operator Example Meaning << a << n Bitwise left shift by n places >> a >> n Bitwise right shift by n places

#### Python Code (Solution)

Here is the Python code for our Truth Table Generator function truthTable() which takes two parameters:

• A Boolean expression: e.g. A AND NOT (B OR C)
• The number of inputs: either 2, 3 or 4: A, B, C and D