ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
x = 7
print(x // 2 if x % 2 else x / 2, x > 3 > 2, not x > 3 == 4)
  1. A. 3.5 True True
  2. B. 3 False False
  3. C. 3.5 False True
  4. D. 3 True True

Correct answer: D. 3 True True

7 is odd, so the conditional gives 7 // 2 = 3. The chained comparison x > 3 > 2 means x > 3 and 3 > 2, which is True. The comparison x > 3 == 4 is the chain (x > 3) and (3 == 4), which is False, so `not` of it is True.

More Python Programming questions

Exams that ask this topic