Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Fraction:
- def __init__(self, numerator, denominator):
- self.numerator = numerator
- self.denominator = denominator
- self.simplify()
- if self.denominator == 1:
- # convert self to int of value numerator
- def simplify(self):
- div = gcd(self.numerator, self.denominator)
- self.numerator //= div
- self.denominator //= div
- def convert(fraction):
- if fraction.denominator == 1:
- return fraction.numerator # int
- else:
- return fraction # Fraction
- f = Fraction(3, 1)
- f = convert(f)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement