integers = [int(number) for number in input().split()]
K = int(input())
triplets = []
for i in range(len(integers)):
for j in range(i+1,len(integers)):
for k in range(j+1, len(integers)):
tmp = tuple(sorted([integers[i], integers[j], integers[k]]))
if sum(tmp) == K:
if tmp not in triplets:
triplets.append(tmp)
triplets_tuple = tuple(sorted(triplets))
print(*triplets_tuple, sep='\n')
It should also print if there is no triplets matching it should print
Input:
1 5 6 3 5 11
30
Output:
No Matching Triplets Found
integers = [int(number) for number in input().split()]
K = int(input())
triplets = []
for i in range(len(integers)):
for j in range(i+1,len(integers)):
for k in range(j+1, len(integers)):
tmp = tuple(sorted([integers[i], integers[j], integers[k]]))
if sum(tmp) == K:
if tmp not in triplets:
triplets.append(tmp)
triplets_tuple = tuple(sorted(triplets))
if(len(triplets_tuple)>0):
print(*triplets_tuple,sep='\n')
else:
print('No Matching Triplets Found\n')
Comments
Leave a comment