ProgrammingVery hardJEE Advanced · CAT placement

What is printed?

What is printed?
from decimal import Decimal
from fractions import Fraction
print(0.1 + 0.2 == 0.3, Decimal('0.1') + Decimal('0.2') == Decimal('0.3'), Decimal(0.1) == Decimal('0.1'), Fraction(1, 10) == 0.1)
  1. A. False True False True
  2. B. False True True False
  3. C. True True False False
  4. D. False True False False

Correct answer: D. False True False False

Decimal('0.1') is exact, so decimal addition gives 0.3 exactly. Decimal(0.1) keeps the float's binary value, and a Fraction compares exactly with the float, which is not one tenth.

More Python Programming questions

Exams that ask this topic