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'))- A. 2 3 3 True
- B. 2 4 2 False
- C. 2 4 2 True
- 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
- What is printed? python x = 'a,b;c' print(x.split(',', 1), x.split(';')[0].split(','), [t for t in x.replace(';', ',').split(',') if t]…
- What is printed? python print(sorted(['10', '9', '100', '8'], key=len), sorted(['10', '9', '100', '8'], key=int))
- What is printed? python from math import isqrt print(isqrt(1030), isqrt(99), isqrt(1030 - 1))
- What is printed? python print(sum(1 for in range(105) if '7' in str()), len(str(sum(1 for in range(105) if '7' in str()))))
- What is printed? python print('%s' % (1,), '%s' % ((1,),), '%r' % ((1, 2),))
- What is printed? python print(1 if True else 0 or 2, not 0 or 3, (not 0) or 3, 0 or '' or None)