ProgrammingVery hardJEE Advanced · CAT placement

What is printed?

What is printed?
from decimal import Decimal, ROUND_HALF_EVEN
print(Decimal('2.5').quantize(Decimal('1'), rounding=ROUND_HALF_EVEN), Decimal('3.5').quantize(Decimal('1')), round(Decimal('2.5')), Decimal('0.1') * 3 == Decimal('0.3'))
  1. A. 2 3 3 True
  2. B. 2 4 2 False
  3. C. 2 4 2 True
  4. D. 3 4 2 True

Correct answer: C. 2 4 2 True

Decimal quantize uses half-to-even by default, so 2.5 goes to 2 and 3.5 goes to 4. round() on a Decimal also rounds half to even, and exact decimal arithmetic makes 0.1 * 3 equal to 0.3.

More Python Programming questions

Exams that ask this topic