ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
from itertools import combinations print(sum(1 for r in range(5) for c in combinations([1, 2, 3, 4], r) if sum(c) == 5))
- A. 1
- B. 3
- C. 4
- D. 2
Correct answer: D. 2
The subsets with sum 5 are {1, 4} and {2, 3}. Every other subset of these numbers sums to a different value.
More Python Programming questions
- What is printed? python print([i ^ (i >> 1) for i in range(4)])
- What is printed? python print(pow(6, -1, 11), pow(4, -1, 9))
- What is printed? python print(int.frombytes(b'x01x00', 'big'), int.frombytes(b'x01x00', 'little'))
- What is printed? python print((255).tobytes(2, 'big'), (1).tobytes(3, 'little'))
- What is printed? python print(sorted(range(10), key=lambda x: (x % 3, -x))[:4])
- What is printed? python print(''.join(sorted('banana', reverse=True)), len(set('abcABC'.lower())), 'ABC'.isupper())