# A 4 input nand gate implemented with AND2 and NOT # gates # # Authors: David Kauchak # # DON'T DO THIS FOR THE ASSIGNMENT, INSTEAD # COPY THE STARTER CODE INTO YOUR ASSIGNMENT AND # ADD YOUR ADDITIONAL FUNCTIONALITY! execfile("assign5-starter.py") class Nand4: def __init__(self, in0, in1, in2, in3, out): andOut1 = Node(0) AndGate2(in0, in1, andOut1) andOut2 = Node(0) AndGate2(in2, in3, andOut2) andOut3 = Node(0) AndGate2(andOut1, andOut2, andOut3) NotGate1(andOut3, out) def simple_test(): # construct the wires in0 = Node(0) in1 = Node(0) in2 = Node(0) in3 = Node(0) out = Node(0) # construct the gate Nand4(in0, in1, in2, in3, out) # try out a few values print out.get_state() # Should be 1: inputs are all 0 currently in0.set_state(1) print out.get_state() # should be 1 in1.set_state(1) print out.get_state() # should be 1 in2.set_state(1) in3.set_state(1) print out.get_state() # should be 0 simple_test()