class Fraction:
def __init__(self,numerator = 0, denominator = 1):
if denominator == 0:
raise ZeroDivisionError("denominator cannot be zero")
if numerator == 0:
self._numerator = 0
self._denomoinator = 1
else:
if(numerator<0 and denominator>0)or(numerator>0 and denominator<0):
flag = -1
else:
flag = 1
a = abs(numerator)
b = abs(denominator)
while a%b != 0:
tempA = a
tempB = b
a = tempB
b = tempA % tempB
self._numerator = abs(numerator)//b*flag
self._denominator = abs(denominator)//b
# 请在此处添加代码 #
#根据测试用例的,重载某些方法,实现定制类#
# *************begin************#
def __lt__(self,other):
left = self._numerator * other._denominator
right = other._numerator * self._denominator
if left < right:return True
return False
def __eq__(self,other):
left = self._numerator * other._denominator
right = other._numerator * self._denominator
if left == right:return True
return False
# **************end*************#
a = int(input())
b = int(input())
frac1 = Fraction(a,b)
c = int(input())
d = int(input())
frac2 = Fraction(c,d)
print(frac1<frac2)
print(frac1==frac2)
python 重载小于等于运算符
最新推荐文章于 2024-07-31 14:30:10 发布