ProgrammingVery hardTCS NQT · Accenture

What is printed?

What is printed?
print(round(-1234.5, -2), round(123456.0, -3), round(0.0, 2), round(1e-7, 7))
  1. A. -1200.0 123000.0 0.0 1e-07
  2. B. -1300.0 123000.0 0.0 1e-07
  3. C. -1200.0 123200.0 0.0 1e-07
  4. D. -1200.0 123000.0 0.0 1e-7

Correct answer: A. -1200.0 123000.0 0.0 1e-07

Rounding a float to a negative number of places returns a float, so -1234.5 goes to -1200.0 and 123456.0 goes to 123000.0. Rounding 1e-7 to seven places keeps it as 1e-07 in repr.

More Python Programming questions

Exams that ask this topic