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')))- A. 0.333 True 1.1 1E+2
- B. 0.3333 False 1.10 100
- C. 0.3333 True 1.1 100
- 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
- What is printed? python print(sorted([(2, 'b'), (1, 'z'), (2, 'a')], reverse=True))
- What is printed? python print(7 / 2 // 1, 7 // 2 / 1, -7 / 2 // 1, 7 % 2.5)
- What is printed? python print('abc'.find(''), 'abc'.count(''), ''.split(), ''.split(','))
- What is printed? python from fractions import Fraction print(Fraction(1, 3) == 1/3, Fraction(1, 3) == Fraction('0.3333333333333333')…
- What is printed? python print('Hello, World'.swapcase(), 'hello world'.title(), "it's here".capitalize(), 'ABC'.isupper())
- What is printed? python print(float('9007199254740993') == 9007199254740993, int(float('9007199254740993')), int(9007199254740993.0))