class LogicGate:#电路实现的超级类 def __init__(self,label): self.label=label#逻辑门的名字 self.output=None#逻辑门的输出,每个逻辑门只有一个输出,是所有逻辑门的共同的属性 def getlabel(self): return self.label#返回逻辑门名称 后面用于打印 def getoutput(self): self.output=self.performGateLogic()#在子类实现具体的方法 用于逻辑门具体输出什么信号的方法。 return self.outputclass BinaryGate(LogicGate):#2端引脚的逻辑门的父类 def __init__(self,label): super().__init__(label) self.PinA=None#引脚A self.PinB=None#引脚B def getPinA(self): if self.PinA==None: return int(input("输入引脚A"+":"+self.getlabel()+"---->")) else: return self.PinA.getFrom().getoutput()#这里调用orgate B引脚接也就是B引脚接得与逻辑门的输出函数 def getPinB(self): if self.PinB==None: return int(input("输入引脚B"+":"+self.getlabel()+"---->")) else
python类实现逻辑门电路_python 逻辑门电路程序练习题,用于理解继承概念
最新推荐文章于 2022-04-21 13:45:59 发布