-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpr4.py
More file actions
15 lines (14 loc) · 689 Bytes
/
Copy pathpr4.py
File metadata and controls
15 lines (14 loc) · 689 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
from itertools import combinations
#The first line of input will contain space-separated integers.
values =[int(i) for i in input('Enter space-separated integers: ').split()]
values.sort()
#The second line of input will contain an integer, denoting K.
K = int(input('Enter K: '))
#The output should be containing the count of all unique combinations of numbers whose sum is equal to K
counterUniqueCombinations=0
for i in range(1, len(values)+1):
com =list(set(combinations(values, i)))
for combination in com:
if sum(combination) == K:
counterUniqueCombinations += 1
print(f"The count of all unique combinations is: {counterUniqueCombinations}")