Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class LogicGate:
- def __init__(self, name):
- self.name = name
- self.pinA = None
- self.pinB = None
- def set_pins(self, pinA, pinB):
- self.pinA = pinA
- self.pinB = pinB
- class HalfAdder(LogicGate):
- def __init__(self, name):
- super().__init__(name)
- self.xor_gate = XorGate("xor1")
- self.and_gate = AndGate("and1")
- def getOutput(self):
- if self.pinA is None or self.pinB is None:
- return "Pins not set. Cannot perform gate logic."
- self.xor_gate.pinA = self.pinA
- self.xor_gate.pinB = self.pinB
- self.and_gate.pinA = self.pinA
- self.and_gate.pinB = self.pinB
- ## OR, if you implemented set_pins ##
- self.xor_gate.set_pins(self.pinA, self.pinB)
- self.and_gate.set_pins(self.pinA, self.pinB)
- #####################################
- gate_sum = self.xor_gate.getOutput()
- gate_carry = self.and_gate.getOutput()
- return gate_sum, gate_carry
- class BinaryGate(LogicGate):
- pass
- class AndGate(BinaryGate):
- pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement