Homework Hack

Review the instructions and examples in the lesson and create a truth table using Python. Additionally look up and learn about De Morgan’s Law and see how it can be used to create a boolean expression.

def de_morgan_law():
    print(f"{'A':<5} {'B':<5} {'Result'}")
    values = [False, True]
    
    for A in values:
        for B in values:
            # Applying De Morgan's first law: not (A and B) == (not A or not B)
            result = not (A and B) == (not A or not B)
            print(f"{A!s:<5} {B!s:<5} {result!s:<5}")
            
# Run the function to display the truth table
de_morgan_law()
A     B     Result
False False True 
False True  True 
True  False True 
True  True  True