#
# Operator Overloading
#
class Quantity:
def __init__(self, value):
self.value = value
def __add__(self, other):
new_value = self.value + other.value
return Quantity(new_value)
def __sub__(self, other):
new_value = self.value - other.value
return Quantity(new_value)
def __mul__(self, other):
new_value = self.value * other.value
return Quantity(new_value)
def __str__(self):
return "Quantity["+ str(self.value) +"]"
def __eq__(self, other):
return self.value == other.value
def __gt__(self, other):
return self.value > other.value
def __ge__(self, other):
return self.value >= other.value
def __lt__(self, other):
return self.value < other.value
def __le__(self, other):
return self.value <= other.value
def main():
q1 = Quantity(10)
q2 = Quantity(20)
q3 = q1 + q2
print(q3)
print(q1<q2)
main()
IwojIE9wZXJhdG9yIE92ZXJsb2FkaW5nCiMKY2xhc3MgUXVhbnRpdHk6CgogICAgICBkZWYgX19pbml0X18oc2VsZiwgdmFsdWUpOgogICAgICAgICAgc2VsZi52YWx1ZSA9IHZhbHVlCgogICAgICBkZWYgX19hZGRfXyhzZWxmLCBvdGhlcik6CiAgICAgICAgICAgbmV3X3ZhbHVlID0gc2VsZi52YWx1ZSArIG90aGVyLnZhbHVlCiAgICAgICAgICAgcmV0dXJuIFF1YW50aXR5KG5ld192YWx1ZSkKCiAgICAgIGRlZiBfX3N1Yl9fKHNlbGYsIG90aGVyKToKICAgICAgICAgIG5ld192YWx1ZSA9IHNlbGYudmFsdWUgLSBvdGhlci52YWx1ZQogICAgICAgICAgcmV0dXJuIFF1YW50aXR5KG5ld192YWx1ZSkKCiAgICAgIGRlZiBfX211bF9fKHNlbGYsIG90aGVyKToKICAgICAgICAgIG5ld192YWx1ZSA9IHNlbGYudmFsdWUgKiBvdGhlci52YWx1ZQogICAgICAgICAgcmV0dXJuIFF1YW50aXR5KG5ld192YWx1ZSkKCiAgICAgIGRlZiBfX3N0cl9fKHNlbGYpOgogICAgICAgICAgcmV0dXJuICJRdWFudGl0eVsiKyBzdHIoc2VsZi52YWx1ZSkgKyJdIgoKICAgICAgZGVmIF9fZXFfXyhzZWxmLCBvdGhlcik6CiAgICAgICAgICByZXR1cm4gc2VsZi52YWx1ZSA9PSBvdGhlci52YWx1ZQoKICAgICAgZGVmIF9fZ3RfXyhzZWxmLCBvdGhlcik6CiAgICAgICAgICByZXR1cm4gc2VsZi52YWx1ZSA+IG90aGVyLnZhbHVlCgogICAgICBkZWYgX19nZV9fKHNlbGYsIG90aGVyKToKICAgICAgICAgIHJldHVybiBzZWxmLnZhbHVlID49IG90aGVyLnZhbHVlCgogICAgICBkZWYgX19sdF9fKHNlbGYsIG90aGVyKToKICAgICAgICAgIHJldHVybiBzZWxmLnZhbHVlIDwgb3RoZXIudmFsdWUKCiAgICAgIGRlZiBfX2xlX18oc2VsZiwgb3RoZXIpOgogICAgICAgICAgcmV0dXJuIHNlbGYudmFsdWUgPD0gb3RoZXIudmFsdWUKZGVmIG1haW4oKToKICAgIHExID0gUXVhbnRpdHkoMTApCiAgICBxMiA9IFF1YW50aXR5KDIwKQogICAgcTMgPSBxMSArIHEyCiAgICBwcmludChxMykKICAgIHByaW50KHExPHEyKQptYWluKCk=