ProgrammingModerateTCS NQT · Infosys

What is printed?

What is printed?
t = 3
print(t // 2 if t % 2 else t / 2, 1 if t else 0, t and 0, t or 0, not t)
  1. A. 1 1 0 0 False
  2. B. 1.5 1 0 3 False
  3. C. 1 1 0 3 False
  4. D. 1 1 3 3 True

Correct answer: C. 1 1 0 3 False

t % 2 is 1, so the conditional picks t // 2 = 1. and returns its first falsy operand or the last value, so t and 0 is 0, while or returns the first truthy value, 3.

More Python Programming questions

Exams that ask this topic