ProgrammingModerateGATE CS · Product-company placement
What is printed?
What is printed?
count = 0
for i in range(1, 4):
for j in range(i):
if (i + j) % 2:
continue
count += 1
print(count, i, j)- A. 3 3 2
- B. 2 3 2
- C. 2 4 3
- D. 2 3 3
Correct answer: B. 2 3 2
Of the pairs (1,0), (2,0), (2,1), (3,0), (3,1), (3,2), only (2,0) and (3,1) have an even sum; continue skips the rest, so count is 2. After the loops, i and j keep their last values 3 and 2.
More Python Programming questions
- What is printed? python a = [4, 2, 7] b = a b.sort() c = sorted(a, reverse=True) print(a, c, a is b, c is a)
- What is printed? python s = "banana" print(s.replace("a", "o", 2), s.upper().count("A"), s[::2], s.startswith(("x", "ba")))
- What is printed? python d = {"x": [1, 2], "y": [3]} flat = [v for vs in d.values() for v in vs] lengths = {k: len(v) for k, v in…
- What is printed? python def f(n): out = [] while n: n, r = divmod(n, -2) if r < 0: n, r = n + 1, r + 2 out.append(str(r)) return…
- What is printed? python def gen(n): if n == 0: yield "" return for s in gen(n - 1): yield s + "0" if not s.endswith("1"): yield s + "1"…
- What is printed? python cache = {} def ways(n): if n < 0: return 0 if n == 0: return 1 if n not in cache: cache[n] = ways(n - 1) + ways(n…