Answer to Question #211839 in Python for sudheer

Question #211839

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)):

      a = integers[i]

      b = integers[j]

      c = integers[k]

      if a+b+c == K:

        triplets.append(tuple((a,b,c))

sorted_triplets=[]

for tripl in triplets:

  item = sorted(tripl)

  sorted_triplets.append(item)

triplets= sorted(sorted_triplets) output:[0, 8, 21] output should be like this:(0, 8, 21)

[0, 12, 17] (0, 12, 17)

[8, 9, 12] (8, 9, 12)

if len(triplets)!=0:

  for triplet in triplets:

    triplet=sorted(triplet)

    print(triplet)

else:

  print("No Matching Triplets Found")


1
Expert's answer
2021-07-02T04:10:18-0400


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)):


      a = integers[i]


      b = integers[j]


      c = integers[k]


      if a+b+c == K:


        triplets.append(tuple((a,b,c)))


sorted_triplets=[]


for tripl in triplets:


  item = sorted(tripl)


  sorted_triplets.append(item)


triplets= sorted(sorted_triplets)



if len(triplets)!=0:


  for triplet in triplets:


    triplet=sorted(triplet)


    print(tuple((triplet)))


else:


  print("No Matching Triplets Found")

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