im almost done with my Class Rational, having a little problem when implementing comparison.
when i compare a Rational number with int, if the Rational is the left operand, then all is well, but when the comparison is int < Rational, it doesn't work.. having this problem with methods like : __lt__
, __gr__
, __ge__
__le__
.
one of my methods:
def __lt__(self,other):
n1=self.n
d1=self.d
if isinstance(other,Rational):
n2=other.n
d2=other.d
elif isinstance(other,int):
n2=other
d2=1
return (n1/d1)<(n2/d2)
for example: