ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
print(list(map(round, [0.5, 1.5, 2.5, -0.5, -1.5])), list(map(int, [0.5, 1.5, 2.5, -0.5, -1.5])))
  1. A. [0, 2, 2, 0, -2] [0, 1, 2, 0, -1]
  2. B. [0, 2, 2, 0, -2] [0, 1, 3, 0, -1]
  3. C. [1, 2, 3, -1, -2] [0, 1, 2, 0, -1]
  4. D. [0, 2, 2, 0, -1] [0, 1, 2, 0, -1]

Correct answer: A. [0, 2, 2, 0, -2] [0, 1, 2, 0, -1]

round uses half-to-even, so 0.5 becomes 0, 1.5 becomes 2, 2.5 becomes 2, and -1.5 becomes -2. int truncates toward zero, so the same halves give 0, 1, 2, 0 and -1.

More Python Programming questions

Exams that ask this topic