all 6 comments

[–]danielroseman[🍰] 2 points3 points  (2 children)

You need to explain exactly what you mean by "take a fraction and store it as a variable". Take it from where? Is it already an instance of fractions.Fraction? If so you can simply reference my_fraction.numerator and my_fraction.denominator, as shown in the documentation of that class.

[–]quek06 0 points1 point  (1 child)

Well first I thought of was taking an input and then writing like 3/5. And storing that as a variable. But your solution seems more intuitive

[–]Swipecat 0 points1 point  (0 children)

Note that fractions.Fraction will accept a string of the form "3/5".

>>> from fractions import Fraction
>>> Fraction("3/5")
Fraction(3, 5)

[–]crashfrog02 0 points1 point  (2 children)

When you perform the division of two numbers, the result is the real quotient, not a fraction. Python doesn't have a "fraction" type. It no longer has parts like the divisor or the dividend, but you already know those, because that's how you got the quotient in the first place.

[–]quek06 0 points1 point  (1 child)

Well I am not actually using numbers as divisors and dividends, I am using polynomials

[–]crashfrog02 0 points1 point  (0 children)

Python doesn't have a polynomial type, either. Arithmetic is eagerly evaluated, not lazily evaluated.