ProgrammingVery hardCAT · MBA placement
What is printed?
What is printed?
print(round(2.5), round(3.5), round(-0.5), round(0.5 + 1e-16))
- A. 2 3 0 1
- B. 3 4 -1 1
- C. 2 4 0 1
- D. 2 4 0 0
Correct answer: C. 2 4 0 1
round() uses round-half-to-even only for exact halves, so 2.5 becomes 2 and 3.5 becomes 4. The int result of round(-0.5) is 0, and 0.5 + 1e-16 is slightly above one half, so it rounds up to 1.
More Python Programming questions
- What is printed? python print('ß'.upper(), 'Dž'.lower(), len('ß'.upper()), 'İ'.lower() == 'i')
- What is printed? python import math print(f'{-0.0}', -0.0 == 0.0, math.copysign(1, -0.0))
- What is printed? python print(1 == 1.0, hash(1) == hash(1.0), {1: 'a'}[1.0], True + 1.0)
- What is printed? python print(sorted([3, -3, 2, -2, 1], key=abs))
- What is printed? python print(f'{-1.5:+.1f}', f'{0.5:.0f}', f'{1.5:.0f}', f'{-0.04:.1f}')
- What is printed? python print(format('x', '>4') + '|' + format(3.14159, '^9.2f') + '|' + format(42, '+') + '|' + format(1234567, ','))