Explanation:
1. Import Fraction
from fractions import Fraction
The fractions module provides the Fraction class for working with exact rational numbers.
For example:
Fraction(3, 4)
represents exactly:
3/4
Unlike floating-point numbers, Fraction keeps the result exact.
2. Create and Multiply Fractions
x = Fraction(3, 4) * Fraction(8, 9)
Here, two fractions are created:
Fraction(3, 4) → 3/4
Fraction(8, 9) → 8/9
Python multiplies them:
3/4 × 8/9
3. Simplify the Result
Multiply the numerators:
3 × 8 = 24
Multiply the denominators:
4 × 9 = 36
So:
24/36
Python automatically simplifies this fraction:
24/36 = 2/3
Therefore:
x
contains:
2/3
4. print(x)
print(x)
The print() function displays the value stored in x.
✅ Final Output
2/3

0 Comments:
Post a Comment