class Cal(object):
_history = []
def __init__(self, v1, v2):
if isinstance(v1, int):
self.v1 = v1
if isinstance(v2, int):
self.v2 = v2
def add(self):
result = self.v1+self.v2
Cal._history.append("add : %d+%d=%d" % (self.v1, self.v2, result))
return result
def subtract(self):
result = self.v1-self.v2
Cal._history.append("subtract : %d-%d=%d" % (self.v1, self.v2, result))
return result
def setV1(self, v):
if isinstance(v, int):
self.v1 = v
def getV1(self):
return self.v1
@classmethod
def history(cls):
for item in Cal._history:
print(item)
def info(self):
return "Cal => v1 : %d, v2 : %d" % (self.v1, self.v2)
class CalMultiply(Cal):
def multiply(self):
result = self.v1*self.v2
Cal._history.append("multiply : %d*%d=%d" % (self.v1, self.v2, result))
return result
def info(self):
return "CalMultiply => %s" % super().info()
class CalDivide(CalMultiply):
def divide(self):
result = self.v1/self.v2
Cal._history.append("divide : %d/%d=%d" % (self.v1, self.v2, result))
return result
def info(self):
return "CalDivide => %s" % super().info()
c0 = Cal(30, 60)
print(c0.info())
c1 = CalMultiply(10,10)
print(c1.info())
c2 = CalDivide(20,10)
print(c2.info())
Y2xhc3MgQ2FsKG9iamVjdCk6CiAgICBfaGlzdG9yeSA9IFtdCiAgICBkZWYgX19pbml0X18oc2VsZiwgdjEsIHYyKToKICAgICAgICBpZiBpc2luc3RhbmNlKHYxLCBpbnQpOgogICAgICAgICAgICBzZWxmLnYxID0gdjEKICAgICAgICBpZiBpc2luc3RhbmNlKHYyLCBpbnQpOgogICAgICAgICAgICBzZWxmLnYyID0gdjIKICAgIGRlZiBhZGQoc2VsZik6CiAgICAgICAgcmVzdWx0ID0gc2VsZi52MStzZWxmLnYyCiAgICAgICAgQ2FsLl9oaXN0b3J5LmFwcGVuZCgiYWRkIDogJWQrJWQ9JWQiICUgKHNlbGYudjEsIHNlbGYudjIsIHJlc3VsdCkpCiAgICAgICAgcmV0dXJuIHJlc3VsdAogICAgZGVmIHN1YnRyYWN0KHNlbGYpOgogICAgICAgIHJlc3VsdCA9IHNlbGYudjEtc2VsZi52MgogICAgICAgIENhbC5faGlzdG9yeS5hcHBlbmQoInN1YnRyYWN0IDogJWQtJWQ9JWQiICUgKHNlbGYudjEsIHNlbGYudjIsIHJlc3VsdCkpCiAgICAgICAgcmV0dXJuIHJlc3VsdAogICAgZGVmIHNldFYxKHNlbGYsIHYpOgogICAgICAgIGlmIGlzaW5zdGFuY2UodiwgaW50KToKICAgICAgICAgICAgc2VsZi52MSA9IHYKICAgIGRlZiBnZXRWMShzZWxmKToKICAgICAgICByZXR1cm4gc2VsZi52MQogICAgQGNsYXNzbWV0aG9kCiAgICBkZWYgaGlzdG9yeShjbHMpOgogICAgICAgIGZvciBpdGVtIGluIENhbC5faGlzdG9yeToKICAgICAgICAgICAgcHJpbnQoaXRlbSkKICAgIGRlZiBpbmZvKHNlbGYpOgogICAgICAgIHJldHVybiAiQ2FsID0+IHYxIDogJWQsIHYyIDogJWQiICUgKHNlbGYudjEsIHNlbGYudjIpCmNsYXNzIENhbE11bHRpcGx5KENhbCk6CiAgICBkZWYgbXVsdGlwbHkoc2VsZik6CiAgICAgICAgcmVzdWx0ID0gc2VsZi52MSpzZWxmLnYyCiAgICAgICAgQ2FsLl9oaXN0b3J5LmFwcGVuZCgibXVsdGlwbHkgOiAlZColZD0lZCIgJSAoc2VsZi52MSwgc2VsZi52MiwgcmVzdWx0KSkKICAgICAgICByZXR1cm4gcmVzdWx0CiAgICBkZWYgaW5mbyhzZWxmKToKICAgICAgICByZXR1cm4gIkNhbE11bHRpcGx5ID0+ICVzIiAlIHN1cGVyKCkuaW5mbygpCmNsYXNzIENhbERpdmlkZShDYWxNdWx0aXBseSk6CiAgICBkZWYgZGl2aWRlKHNlbGYpOgogICAgICAgIHJlc3VsdCA9IHNlbGYudjEvc2VsZi52MgogICAgICAgIENhbC5faGlzdG9yeS5hcHBlbmQoImRpdmlkZSA6ICVkLyVkPSVkIiAlIChzZWxmLnYxLCBzZWxmLnYyLCByZXN1bHQpKQogICAgICAgIHJldHVybiByZXN1bHQKICAgIGRlZiBpbmZvKHNlbGYpOgogICAgICAgIHJldHVybiAiQ2FsRGl2aWRlID0+ICVzIiAlIHN1cGVyKCkuaW5mbygpCgpjMCA9IENhbCgzMCwgNjApCnByaW50KGMwLmluZm8oKSkKYzEgPSBDYWxNdWx0aXBseSgxMCwxMCkKcHJpbnQoYzEuaW5mbygpKQpjMiA9IENhbERpdmlkZSgyMCwxMCkKcHJpbnQoYzIuaW5mbygpKQo=