ProgrammingVery hardTCS NQT · Accenture

What is printed?

What is printed?
print(round(1234.5678, -2), round(1234.5678, 2), round(-0.0001, 3), round(5.5), round(6.5))
  1. A. 1200 1234.57 0.0 6 6
  2. B. 1200.0 1234.57 -0.0 5 6
  3. C. 1200.0 1234.57 0.0 6 7
  4. D. 1200.0 1234.57 -0.0 6 6

Correct answer: D. 1200.0 1234.57 -0.0 6 6

round with a negative digit count on a float returns a float, so 1234.5678 becomes 1200.0. Rounding to three places keeps the sign of the small negative value, giving -0.0, while round(5.5) and round(6.5) both go to the even integer 6.

More Python Programming questions

Exams that ask this topic