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
- Free shipping in Python
- Raj has ordered two electronic items Python | Assignment Expert
- Team Points in Python
- Ticket selling in Cricket Stadium using Python | Assignment Expert
- Split the sentence in Python
- String Slicing in JavaScript
- First and Last Digits in Python | Assignment Expert
- List Indexing in Python
- Date Format in Python | Assignment Expert
- New Year Countdown in Python
- Add Two Polynomials in Python
- Sum of even numbers in Python | Assignment Expert
- Evens and Odds in Python
- A Game of Letters in Python
- Sum of non-primes in Python
- Smallest Missing Number in Python
- String Rotation in Python
- Secret Message in Python
- Word Mix in Python
- Single Digit Number in Python
- Shift Numbers in Python | Assignment Expert
- Weekend in Python
- Shift Numbers in Python | Assignment Expert
- Temperature Conversion in Python
- Special Characters in Python
- Sum of Prime Numbers in the Input in Python