given an array of n integers find and print all the unique triplets
values = input("Enter series of integers to convert to array:")
integers_entered = [int(value) for value in values]
target_value = int(input("Enter the target value for the triplets(Value that all the triplets should add up to):"))
calculated_triplets = []
for item in range(len(integers_entered)):
for another_item in range(item+1,len(integers_entered)):
for third_item in range(another_item+1,len(integers_entered)):
a = integers_entered[item]
b = integers_entered[another_item]
c = integers_entered[third_item]
if a + b + c == target_value:
calculated_triplets.append(tuple((a,b,c)))
if len(calculated_triplets) != 0:
for triplet in calculated_triplets:
print(triplet)
else:
print("No Matching Triplets Found In This Time")
Comments
Leave a comment