ProgrammingModerateGATE CS · Product-company placement

What is printed?

What is printed?
x = 7
kind = "even" if x % 2 == 0 else "odd"
sign = "pos" if x > 0 else "zero" if x == 0 else "neg"
print(kind, sign, ["no", "yes"][x > 5])
  1. A. odd pos yes
  2. B. odd pos no
  3. C. even pos yes
  4. D. odd zero yes

Correct answer: A. odd pos yes

Conditional expressions chain right-to-left like if/elif/else. A bool used as an index is 0 or 1, so ['no', 'yes'][True] is 'yes'.

More Python Programming questions

Exams that ask this topic