ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
from math import ceil
print(ceil(7 / 2), -(-7 // 2), (7 + 2 - 1) // 2)
  1. A. 3 3 4
  2. B. 4 3 3
  3. C. 3 4 4
  4. D. 4 4 4

Correct answer: D. 4 4 4

ceil(3.5) is 4. -(-7 // 2) uses floor division on -7 // 2 = -4, which becomes 4 after the negation. (7 + 2 - 1) // 2 = 4 is the usual integer ceiling trick.

More Python Programming questions

Exams that ask this topic