Answer to Question #221656 in Python for balaji

Question #221656

given a list of integers , write a program to print the count of all possible unique combinations of numbers whose sum is equal to k.


1
Expert's answer
2021-07-31T07:16:44-0400
from itertools import combinations
nums = [int(x) for x in input().split()]
k = int(input())
count = 0
for i in range(1, len(nums)+1):
    for c in combinations(nums, i):
        if sum(c) == k:
            count += 1
print(count)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS