ProgrammingModerateCAT · MBA placement

What is printed?

What is printed?
from fractions import Fraction
x = Fraction(1, 3) + Fraction(1, 6)
print(x, x.numerator, Fraction(6, -8))
  1. A. 1/2 1 -3/4
  2. B. 3/4 1 -1/2
  3. C. 1/2 2 -3/4
  4. D. 1/3 1 -3/4

Correct answer: A. 1/2 1 -3/4

Fraction keeps exact rationals and moves the sign to the numerator, so 6/-8 becomes -3/4. The sum 1/3 + 1/6 is exactly 1/2.

More Python Programming questions

Exams that ask this topic