ProgrammingHardJEE Advanced · CAT placement

What is printed?

What is printed?
from decimal import Decimal, getcontext
getcontext().prec = 4
print(Decimal(1) / Decimal(3), Decimal('1.10') == Decimal('1.1'), Decimal('1.10') * 1, str(Decimal('1E+2')))
  1. A. 0.333 True 1.1 1E+2
  2. B. 0.3333 False 1.10 100
  3. C. 0.3333 True 1.1 100
  4. D. 0.3333 True 1.10 1E+2

Correct answer: D. 0.3333 True 1.10 1E+2

The precision of 4 digits makes 1/3 print as 0.3333. Decimal equality ignores trailing zeros, but multiplication keeps the exponent of the operand, so the result still shows 1.10. str() of 1E+2 keeps scientific form.

More Python Programming questions

Exams that ask this topic