ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
print(round(0.5), round(1.5), round(2.5), round(-2.5), round(2.5 + 1e-15))
- A. 0 2 2 -2 3
- B. 0 2 2 -2 2
- C. 1 2 2 -2 3
- D. 0 2 2 -3 3
Correct answer: A. 0 2 2 -2 3
round uses half-to-even at exact halves, so 0.5 becomes 0 and 2.5 becomes 2. Adding a tiny 1e-15 pushes 2.5 past the halfway point, so it rounds to 3.
More Python Programming questions
- What is printed? python print(round(12345, -2), round(12350, -2), round(12250, -2), round(-1234.5, -1))
- What is printed? python print(format(1234.5678, '.2f'), format(1234.5678, '.2e'), format(0.000012345, '.3g'), format(12345.6789, ',.1f'))
- What is printed? python print(str(1.0), str(1e2), str(1.5e-7), str(123456789012345678.0), str(0.1 + 0.7))
- What is printed? python print(1 / 3 3 == 1.0, 2 / 3 3 == 2.0, 10 / 3 3 == 10.0, 0.7 3 == 2.1)
- What is printed? python print(float('nan') < 1, float('nan') > 1, float('nan') != float('nan'))
- What is printed? python import math print(math.isnan(float('nan') 0), math.isinf(1e308 10), math.isfinite(-0.0), math.copysign(1, -0.0))