Answer to Question #224512 in Python for NARASIMHA GUDISA

Question #224512

given an array of n integers find and print all the unique triplets


1
Expert's answer
2021-08-09T02:34:05-0400
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")

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