ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
print(round(3.14159, 3), round(12345, -2), round(0.5), round(1.5), round(2.5, 0))
  1. A. 3.141 12300 0 2 2
  2. B. 3.142 12345 0 2 2.0
  3. C. 3.142 12300 1 2 2
  4. D. 3.142 12300 0 2 2.0

Correct answer: D. 3.142 12300 0 2 2.0

round with a digits argument returns a float for a float input, and round with a negative digits argument on an int returns an int, here 12300. Ties go to the even neighbour, so 0.5 gives 0, 1.5 gives 2 and 2.5 gives 2.0.

More Python Programming questions

Exams that ask this topic