Answer to Question #323292 in Python for Lohithkumar

Question #323292

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.



Input:



The first line of Input will contain space-separated Integer.



The second line of Input will contain an 8nteger,denoting K.




Sample Input:



2 4 6 1 3




Output:



3

1
Expert's answer
2022-04-04T07:48:10-0400
from itertools import combinations




listOfInt = [int(i) for i in input().split()]
k = int(input())
cnt = 0
for i in range(1,len(listOfInt)+1):
	for tmp in combinations(listOfInt, i):
		if sum(tmp) == k:
			cnt += 1
print(cnt)

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