Create a two new gate classes, one called NorGate the other called NandGate. NandGates work like AndGates
Question:
Create a two new gate classes, one called NorGate the other called NandGate. NandGates work like AndGates that have a Not attached to the output. NorGates work lake OrGates that have a Not attached to the output.Create a series of gates that prove the following equality NOT (( A and B) or (C and D)) is that same as NOT( A and B ) and NOT (C and D). Make sure to use some of your new gates in the simulation. in python.
classLogicGate:
def __init__(self,n):
self.name = n
self.output = None
defgetName(self):
return self.name
defgetOutput(self):
self.output = self.performGateLogic()
returnself.output
classBinaryGate(LogicGate):
def __init__(self,n):
LogicGate.__init__(self,n)
self.pinA = None
self.pinB = None
defgetPinA(self):
ifself.pinA == None:
returnint(input("Enter Pin A input for gate "+self.getName()+"-->"))
else:
returnself.pinA.getFrom().getOutput()
defgetPinB(self):
ifself.pinB == None:
returnint(input("Enter Pin B input for gate "+self.getName()+"-->"))
else:
returnself.pinB.getFrom().getOutput()
defsetNextPin(self,source):
ifself.pinA == None:
self.pinA = source
else:
ifself.pinB == None:
self.pinB = source
else:
print("Cannot Connect: NO EMPTY PINS on this gate")
classAndGate(BinaryGate):
def __init__(self,n):
BinaryGate.__init__(self,n)
defperformGateLogic(self):
a = self.getPinA()
b = self.getPinB()
if a==1 and b==1:
return 1
else:
return 0
classOrGate(BinaryGate):
def __init__(self,n):
BinaryGate.__init__(self,n)
defperformGateLogic(self):
a = self.getPinA()
b = self.getPinB()
if a ==1 or b==1:
return 1
else:
return 0
classUnaryGate(LogicGate):
def __init__(self,n):
LogicGate.__init__(self,n)
self.pin = None
defgetPin(self):
ifself.pin == None:
returnint(input("Enter Pin input for gate "+self.getName()+"-->"))
else:
returnself.pin.getFrom().getOutput()
defsetNextPin(self,source):
ifself.pin == None:
self.pin = source
else:
print("Cannot Connect: NO EMPTY PINS on this gate")
classNotGate(UnaryGate):
def __init__(self,n):
UnaryGate.__init__(self,n)
defperformGateLogic(self):
ifself.getPin():
return 0
else:
return 1
class Connector:
def __init__(self, fgate, tgate):
self.fromgate = fgate
self.togate = tgate
tgate.setNextPin(self)
defgetFrom(self):
returnself.fromgate
defgetTo(self):
returnself.togate
def main():
g1 = AndGate("G1")
g2 = AndGate("G2")
g3 = OrGate("G3")
g4 = NotGate("G4")
c1 = Connector(g1,g3)
c2 = Connector(g2,g3)
c3 = Connector(g3,g4)
print(g4.getOutput())
main()
College Algebra Graphs and Models
ISBN: 978-0321845405
5th edition
Authors: Marvin L. Bittinger, Judith A. Beecher, David J. Ellenbogen, Judith A. Penna