Reputation: 139
I'm trying to do this calculation:
from fractions import Fraction
z=4
x=Float(Fraction(1+math.pi,1+2*z**2))
But this results in the following error:
TypeError: both arguments should be Rational instances
If I change pi value for integer value works. But if I use a decimal value shows me that error.
Any idea?
Regards Thanks
Upvotes: 0
Views: 333
Reputation: 14484
Taken from the documented for the fractions
module:
The [two argument constructor] requires that
numerator
anddenominator
are instances of numbers.Rational.
In your snippet, 1+math.pi
is a float
, not an instance of numbers.Rational
, hence the TypeError
.
Upvotes: 1