ProgrammingModerateTCS NQT · Infosys

What is printed?

What is printed?
print(abs(-2**63) == 2**63, abs(-0.0) == 0.0, abs(-2.5) // 1, -2.5 // 1 * -1)
  1. A. True True 2.0 2.0
  2. B. False True 2.0 3.0
  3. C. True False 2.0 3.0
  4. D. True True 2.0 3.0

Correct answer: D. True True 2.0 3.0

abs of a negative int gives its magnitude, and abs(-2.5) // 1 is 2.0. In -2.5 // 1 * -1 the floor division gives -3.0 first, and the multiplication by -1 makes it 3.0.

More Python Programming questions

Exams that ask this topic