ProgrammingVery hardTCS NQT · Accenture
What is printed?
What is printed?
print([] == [] or 1 / 0, [] and 1 / 0, 0 or 1 and 2)
- A. False [] 2
- B. True [] 1
- C. True [] 2
- D. True ZeroDivisionError 2
Correct answer: C. True [] 2
[] == [] is True, so or stops there and never divides by zero. [] is falsy, so and returns it without evaluating the division. 0 or (1 and 2) gives 2.
More Python Programming questions
- What is printed? python print(3 % 2 == 1 and 4 % 2 == 0, 3 // 2 == 1 or 1 / 0)
- What is printed? python print(f'{"":>3}|', f'{"x":^3}|', f'{None!s:>6}|')
- What is printed? python from functools import lrucache @lrucache(maxsize=None) def t(n): if n == 0: return 0 if n < 3: return 1 return t(n…
- What is printed? python from collections import deque def countpaths(g): R, C = len(g), len(g[0]) dist = [[-1] C for in range(R)] ways =…
- What is printed? python def cnt(a, k): pre = {0: 1} s = ans = 0 for x in a: s += x ans += pre.get(s - k, 0) pre[s] = pre.get(s, 0) + 1…
- What is printed? python def twotx(p): b1 = b2 = float('-inf') s1 = s2 = 0 for x in p: b1 = max(b1, -x) s1 = max(s1, b1 + x) b2 = max(b2…