Created
November 16, 2011 17:49
-
-
Save pasali/1370797 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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