operator overloading python stack overflow
class optr_ovrld:
def __init__(self,str1):
self.str1= str1
self.s1 = 0
self.s2 = 0
def __add__(self,other):
res = ""
i = 0
while (i < len(self.str1)) or (i < len(other.str1)):
if (i < len(self.str1)):
res += self.str1[i]
if (i < len(other.str1)):
res += other.str1[i]
i += 1
return res
def __lt__(self,other):
i = 0
while(i<len(self.str1)):
self.s1 += ord(self.str1[i])
i += 1
i = 0
while(i<len(other.str1)):
self.s2 += ord(other.str1[i])
i += 1
if self.s1 < self.s2:
return True
else:
return False
def __le__(self,other):
i = 0
while(i<len(self.str1)):
self.s1 += ord(self.str1[i])
i += 1
i = 0
while(i<len(other.str1)):
self.s2 += ord(other.str1[i])
i += 1
if self.s1 <= self.s2:
return True
else:
return False
def __eq__(self,other):
i = 0
while(i<len(self.str1)):
self.s1 += ord(self.str1[i])
i += 1
i = 0
while(i<len(other.str1)):
self.s2 += ord(other.str1[i])
i += 1
if self.s1 == self.s2:
return True
else:
return False
def __gt__(self,other):
i = 0
while(i<len(self.str1)):
self.s1 += ord(self.str1[i])
i += 1
i = 0
while(i<len(other.str1)):
self.s2 += ord(other.str1[i])
i += 1
if self.s1 > self.s2:
return True
else:
return False
def __ge__(self,other):
i = 0
while(i<len(self.str1)):
self.s1 += ord(self.str1[i])
i += 1
i = 0
while(i<len(other.str1)):
self.s2 += ord(other.str1[i])
i += 1
if self.s1 >= self.s2:
return True
else:
return False
obj1 = optr_ovrld(input("enter 1st string :: "))
obj2 = optr_ovrld(input("enter 2nd string :: "))
print(obj1 + obj2)
print(obj1 < obj2)
print(obj1 > obj2)
print(obj1 <= obj2)
print(obj1 >= obj2)
print(obj1 == obj2)