Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. class Fraction:
  2. def __init__(self, numerator, denominator):
  3. self.numerator = numerator
  4. self.denominator = denominator
  5. self.simplify()
  6.  
  7. if self.denominator == 1:
  8. # convert self to int of value numerator
  9.  
  10. def simplify(self):
  11. div = gcd(self.numerator, self.denominator)
  12. self.numerator //= div
  13. self.denominator //= div
  14.  
  15. def convert(fraction):
  16. if fraction.denominator == 1:
  17. return fraction.numerator # int
  18. else:
  19. return fraction # Fraction
  20.  
  21.  
  22. f = Fraction(3, 1)
  23. f = convert(f)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement