ProgrammingVery hardJEE Advanced · CAT placement

What is printed?

What is printed?
from fractions import Fraction
print(Fraction(1, 3) == 1/3, Fraction(1, 3) == Fraction('0.3333333333333333'), float(Fraction(2, 3)) == 2/3, Fraction(0.1) == 0.1)
  1. A. True False True True
  2. B. False True True True
  3. C. False False True True
  4. D. False False False True

Correct answer: C. False False True True

Comparing a Fraction with a float is exact, and 1/3 is not a float, so the first two comparisons are False. Fraction(0.1) is the exact binary value of the float, so it equals 0.1.

More Python Programming questions

Exams that ask this topic