First page Back Continue Last page Overview Graphics

Fraction Class 3

def __gt__(self, other):

return self.__num * other.__den > other.__num * self.__den

def __ge__(self, other):

return self.__num * other.__den >= other.__num * self.__den

def __lt__(self, other):

return self.__num * other.__den < other.__num * self.__den

def __le__(self, other):

return self.__num * other.__den <= other.__num * self.__den

if __name__ == "__main__":

x = Fraction(2,6)

y = Fraction(3,14)

print(x * y)

print(x / y)

print(x + y)

print(x - y)

if x < y:

print("x < y")

else:

print("x >= y")

print(x)