ProgrammingHardTCS NQT · Wipro pattern

What is printed?

What is printed?
print(0.1 + 0.2 != 0.3, 1 if 0.1 + 0.2 else 0, 0.0 or -0.0 or 'x', 0 and 1 or 2)
  1. A. True 1 x 2
  2. B. False 1 x 2
  3. C. True 0 x 2
  4. D. True 1 0 0 2

Correct answer: A. True 1 x 2

0.1 + 0.2 is not equal to 0.3, and any non-zero float is truthy. 0.0 and -0.0 are both falsy, so or returns the next value, and 0 and 1 is 0, so or 2 gives 2.

More Python Programming questions

Exams that ask this topic