1: simple factory model, factory Model
Class Operate: def _ init _ (self): passclass Add (Operate): def result (self): return (self. a + self. b) class Subduct (Operate): def result (self): return self. a-self. B class Multiply (Operate): def result (self): return self. a * self. bclass Divide (Operate): def result (self): return self. a/self. bclass Factory: # simple Factory, implementing the process of Instantiation and interaction between classes def run (self): op = Operate # Note: a, B, operation is to calculate the 'class attribute' of the parent class Operate so that its subclass can be called directly. The subclass cannot access the instance attribute op of the parent class. a = int (input ('plz input the first number: ') op. operation = input ('plz input operation like (+,-, *,/): ') op. B = int (input ('plz input the second number: ') if (op. operation = '+'): print (Add (). result () elif (op. operation = '-'): print (Subduct (). result () elif (op. operation = '*'): print (Multiply (). result () elif (operation = '/'): print (Divide (). result () Factory (). run ()