Skip to content

Instantly share code, notes, and snippets.

@pasali
Created November 16, 2011 17:49
Show Gist options
  • Save pasali/1370797 to your computer and use it in GitHub Desktop.
Save pasali/1370797 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
#-*-coding:utf-8-*-
class LogicGate:
def __init__(self, n):
self.label = n
def GetLabel(self):
return self.label
def GetOutput(self):
self.output = self.PerGateLogic()
return self.output
class BinaryGate(LogicGate):
def __init__(self, n):
LogicGate.__init__(self, n)
self.pinA = None
self.pinB = None
def GetPinA(self):
return input("enter pin A for " + self.GetLabel() + "==>")
def GetPinB(self):
return input("enter pin B for " + self.GetLabel() + "==>")
class UnaryGate(LogicGate):
def __init__(self, n):
LogicGate.__init__(self, n)
self.pin = None
def GetPin(self):
return input("enter pin for " + self.GetLabel() + "==>")
class AndGate(BinaryGate):
def __init__(self,n):
BinaryGate.__init__(self, n)
def PerGateLogic(self):
a = self.GetPinA()
b = self.GetPinB()
if a == 1 and b == 1:
return 1
else:
return 0
class OrGate(AndGate):
def __init__(self, n):
AndGate.__init__(self,n)
def PerGateLogic(self):
a = self.GetPinA()
b = self.GetPinB()
if a == 0 and b == 0:
return 0
else:
return 1
kap1 = OrGate("K")
print kap1.GetOutput()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment