ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
print(int(3.99999999999999999), int(-3.7), 3.99999999999999999 == 4.0, 3)
  1. A. 3 -3 True 3
  2. B. 4 -3 True 3
  3. C. 4 -4 False 3
  4. D. 4 -3 False 3

Correct answer: B. 4 -3 True 3

The literal 3.99999999999999999 has more digits than a double holds, so it becomes exactly 4.0. int() truncates it to 4, while int(-3.7) truncates toward zero to -3.

More Python Programming questions

Exams that ask this topic