# Untitled

unknown

plain_text

a year ago

2.4 kB

10

Indexable

Never

^{}

# Define logic gates def and_gate(a, b): return a and b def or_gate(a, b): return a or b def not_gate(a): return not a def nand_gate(a, b): return not and_gate(a, b) def nor_gate(a, b): return not or_gate(a, b) def eor_gate(a, b): return a != b def enor_gate(a, b): return not eor_gate(a, b) # Prompt user for input gate = input("Enter the boolean logic gate (using symbols for and, or, not, nand, nor, eor, and enor): ") # Simplify the gate using boolean algebra simplified_gate = gate while True: old_gate = simplified_gate simplified_gate = simplified_gate.replace("not not ", "") # Double negation simplified_gate = simplified_gate.replace("not True", "False") # Not True is False simplified_gate = simplified_gate.replace("not False", "True") # Not False is True simplified_gate = simplified_gate.replace("True and ", "") # True and x is x simplified_gate = simplified_gate.replace(" and True", "") # x and True is x simplified_gate = simplified_gate.replace("False and ", "False") # False and x is False simplified_gate = simplified_gate.replace(" and False", "False") # x and False is False simplified_gate = simplified_gate.replace("True or ", "True") # True or x is True simplified_gate = simplified_gate.replace(" or True", "True") # x or True is True simplified_gate = simplified_gate.replace("False or ", "") # False or x is x simplified_gate = simplified_gate.replace(" or False", "") # x or False is x simplified_gate = simplified_gate.replace("True eor True", "False") # True eor True is False simplified_gate = simplified_gate.replace("False eor False", "False") # False eor False is False simplified_gate = simplified_gate.replace("True eor False", "True") # True eor False is True simplified_gate = simplified_gate.replace("False eor True", "True") # False eor True is True simplified_gate = simplified_gate.replace("True enor True", "True") # True enor True is True simplified_gate = simplified_gate.replace("False enor False", "True") # False enor False is True simplified_gate = simplified_gate.replace("True enor False", "False") # True enor False is False simplified_gate = simplified_gate.replace("False enor True", "False") # False enor True is False if simplified_gate == old_gate: break # Output the simplified gate print("Simplified gate: ", simplified_gate)