>>> from fractions import Fraction
>>> a = Fraction(5,4)
>>> b = Fraction(7,16)
>>> a+b
Fraction(27, 16)
>>> print a + b
27/16
>>> print a * b
35/64
>>>
>>> c = a * b
>>> c.numerator
35
>>> c.denominator
64
>>> float(c)
0.546875
>>> print c.limit_denominator(8)
4/7
>>> print c.limit_denominator(9)
5/9
>>> x = 3.75
>>> y = Fraction(*x.as_integer_ratio())
>>> print y
15/4
>>> a = Fraction(5,4)
>>> b = Fraction(7,16)
>>> a+b
Fraction(27, 16)
>>> print a + b
27/16
>>> print a * b
35/64
>>>
>>> c = a * b
>>> c.numerator
35
>>> c.denominator
64
>>> float(c)
0.546875
>>> print c.limit_denominator(8)
4/7
>>> print c.limit_denominator(9)
5/9
>>> x = 3.75
>>> y = Fraction(*x.as_integer_ratio())
>>> print y
15/4
Comments
Post a Comment
https://gengwg.blogspot.com/