ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
print(round(0.25, 1), round(0.35, 1), round(2.5), round(-0.5))
  1. A. 0.2 0.4 3 -1
  2. B. 0.3 0.3 2 -1
  3. C. 0.2 0.3 2 0
  4. D. 0.3 0.4 2 0

Correct answer: C. 0.2 0.3 2 0

round uses round-half-to-even on the exact binary value. 0.25 is exact, so the tie goes to 0.2. 0.35 is stored slightly below 0.35, giving 0.3. round(-0.5) returns the int 0 because no digits argument was given.

More Python Programming questions

Exams that ask this topic