Add __eq__ in fraction
This commit is contained in:
parent
49b224bedc
commit
6509e0164a
@ -166,13 +166,24 @@ class Fraction(object):
|
|||||||
|
|
||||||
return steps
|
return steps
|
||||||
|
|
||||||
|
def __eq__(self, other):
|
||||||
|
""" == """
|
||||||
|
if type(other) == Fraction:
|
||||||
|
number = other
|
||||||
|
else:
|
||||||
|
number = Fraction(other)
|
||||||
|
|
||||||
|
return self._num * number._denom == self._denom * number._num
|
||||||
|
|
||||||
def __lt__(self, other):
|
def __lt__(self, other):
|
||||||
|
""" < """
|
||||||
if type(other) == Fraction:
|
if type(other) == Fraction:
|
||||||
return (self._num / self._denom) < (other._num / other._denom)
|
return (self._num / self._denom) < (other._num / other._denom)
|
||||||
else:
|
else:
|
||||||
return (self._num / self._denom) < other
|
return (self._num / self._denom) < other
|
||||||
|
|
||||||
def __le__(self, other):
|
def __le__(self, other):
|
||||||
|
""" <= """
|
||||||
if type(other) == Fraction:
|
if type(other) == Fraction:
|
||||||
return (self._num / self._denom) <= (other._num / other._denom)
|
return (self._num / self._denom) <= (other._num / other._denom)
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user