from fractions import gcd
class Fraction:
def __init__(self,numerator,denominator):
assert denominator != 0, "nenner muß nicht null sein"
if denominator < 0:
(numerator,denominator) = (-numerator,-denominator)
gcden = gcd(numerator,denominator)
self.__num = numerator
self.__den = denominator
@property
def numerator(self):
return self.__num
@property
def denominator(self):
return self.__den
def __mult__(self,other):
new_num = self.numerator * other.numerator
new_den = self.denominator * other.denominator
return Fraction(new_num,new_den)
f1 = Fraction(2,6)
f2 = Fraction(5,25)
f3 = f1 * f2
if __name__ == '__main__':
print(f1.numerator,f1.denominator)
print(f2.numerator,f2.denominator)
print('------')
print(f3.numerator,f3.denominator)
it raisis the error
gcden = gcd(numerator,denominator)
Traceback (most recent call last):
File "zwölf.py", line 127, in <module>
f3 = f1 * f2
TypeError: unsupported operand type(s) for *: 'Fraction' and 'Fraction'
What I have tried:
if __name__ == '__main__':
print(f1.numerator,f1.denominator)
print(f2.numerator,f2.denominator)
print('------')
print(f3.numerator,f3.denominator)