ProgrammingVery hardProduct-company MCQ pattern

What is printed?

What is printed?
from fractions import Fraction
print(Fraction(1, 3) + Fraction(1, 6), Fraction(0.5), Fraction('0.1') + Fraction(0.1) == Fraction(1, 5), Fraction(3, -6))
  1. A. 1/2 1/2 True -1/2
  2. B. 1/2 1/2 False 1/3
  3. C. 1/2 1/2 False -1/2
  4. D. 1/2 3/2 False -1/2

Correct answer: C. 1/2 1/2 False -1/2

Fraction(0.1) is built from the exact binary value of the float, which is not exactly 1/10, so the sum is not 1/5. A negative denominator moves the sign to the numerator, giving -1/2.

More Python Programming questions

Exams that ask this topic