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)
- A. 1 1 0 0 False
- B. 1.5 1 0 3 False
- C. 1 1 0 3 False
- 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
- What is printed? python print(int(0.999999999999999999999), round(0.4999999999999999), round(-0.4999999999999999), int(-0.9))
- What is printed? python print(f'{12.0:g}', f'{12.5:g}', f'{0.00001234:g}', f'{123456789:g}', f'{1.5e300:g}')
- What is printed? python print(10 18 10 18 // 10 35, 2 64 // 2 32, 2 64 % 2 32)
- What is printed? python x = 1 << 200 print(x.bitlength(), len(str(x)), x % 1000, (x >> 190) & 0xFF)
- What is printed? python print(f'{210:,}', f'{210:x}', f'{210:b}', f'{-210:>8}'.strip())
- What is printed? python print(str(round(2.5)), str(round(3.5)), round(2.5 + 0.0001), round(-2.5 - 0.0001))