fork download
  1. class Cal(object):
  2. def __init__(self, v1, v2):
  3. if isinstance(v1, int):
  4. self.v1 = v1
  5. if isinstance(v2, int):
  6. self.v2 = v2
  7. def add(self):
  8. return self.v1+self.v2
  9. def subtract(self):
  10. return self.v1-self.v2
  11. def setV1(self, v):
  12. if isinstance(v, int):
  13. self.v1 = v
  14. def getV1(self):
  15. return self.v1
  16. class CalMultiply(Cal):
  17. def multiply(self):
  18. return self.v1*self.v2
  19. class CalDivide(CalMultiply):
  20. def divide(self):
  21. return self.v1/self.v2
  22. c1 = CalMultiply(10,10)
  23. print(c1.add())
  24. print(c1.multiply())
  25. c2 = CalDivide(20,10)
  26. print(c2, c2.add())
  27. print(c2, c2.multiply())
  28. print(c2, c2.divide())
  29.  
Success #stdin #stdout 0.02s 8736KB
stdin
Standard input is empty
stdout
20
100
<__main__.CalDivide object at 0xb753322c> 30
<__main__.CalDivide object at 0xb753322c> 200
<__main__.CalDivide object at 0xb753322c> 2.0