ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
import itertools print(sum(1 for _ in itertools.combinations(range(6), 2)), sum(1 for _ in itertools.permutations(range(4), 2)))
- A. 15 12
- B. 15 16
- C. 12 12
- D. 30 12
Correct answer: A. 15 12
Choosing 2 of 6 without order gives C(6, 2) = 15. Ordered pairs of 2 out of 4 give P(4, 2) = 12.
More Python Programming questions
- Which of the following statements about Python's sort is correct for CP problems?
- What is printed? python def solve(n): if n == 0: return [] return solve(n // 2) + [n % 2] print(solve(6), solve(0))
- What is printed? python print(divmod(7, -3), 7 % -3, -7 % 3, -7 // 3)
- What is printed? python x = 'aaa' y = list(x) y[0] = 'b' print(x, ''.join(y), x is y)
- What is printed? python grid = [[1, 2], [3, 4]] flat = [v for row in grid for v in row] print(flat, sum(flat) == sum(map(sum, grid)))
- What is printed? python def merge(a, b): out, i, j = [], 0, 0 while i < len(a) and j < len(b): if a[i] <= b[j]: out.append(a[i]); i += 1…