Problem Statement:
Joey wants to find a triplet of integers x, y, and z such that it satisfies these two conditions:
- (y+z)-x <= A
- (y*z)*(-x) <= B
where A and B are given input integers.
Design a Python program that takes two integers as input A and B and prints these triplets. Also, print the count of triplets.
For Example
Input:
Enter A and B: 2 4
Output:
Count of Triplets: 10
Triplets: [0, 0, 0], [0, 0, 1], [0, 0, 2], [0, 1, 0], [0, 1, 1], [0, 2, 0], [1, 0, 0], [1, 0, 1], [1, 1, 0], [2, 0, 0]
Code for Triples with Properties in Python:
#function for finding triplets def findTriplets(A,B): triplets = [] for x in range(A+1): for y in range(A-x+1): for z in range(A-(x+y)+1): if(y+z-x<=A and x*y*z<=B): triplets.append([x,y,z]) return triplets #input the integers A,B=map(int,input("Enter A and B: ").split()) triplets = findTriplets(A,B) #print the output print("Count of Triplets: ",len(triplets)) print("Triplets: ",end=" ") for x in triplets: print(x,end=" ")
Output:

Also Read:
- Hyphenate Letters in Python
- Earthquake in Python | Easy Calculation
- Striped Rectangle in Python
- Perpendicular Words in Python
- Composite Number in Python
- Greatest Among Four Numbers in Python
- Reverse the sentence in Python
- Denominations in Python
- Min and max values in an array in JavaScript
- Keyboard events in JavaScript
- Reaching Ground Floor in Python
- Number of Moves in Python
- Starks Adventure in Python
- Neutralization in Python | Assignment Expert
- Free shipping in Python
- Raj has ordered two electronic items Python | Assignment Expert
- First Place in Python
- Triples with Properties in Python
- Nested list Indexing Python
- Team Points in Python
- Two words combination in Python
- ID Card in Python
- Cipher with a key in Python | Assignment Expert
- Multiple of 5 in Python
- Sandglass Star in Python
- Multiple of 3 in Python | Assignment Expert
- Ticket selling in Cricket Stadium using Python | Assignment Expert
- Sum of List Elements in Python
- All possible subsets in Python
- Names and Nicknames in Python