- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python Program to Determine all Pythagorean Triplets in the Range
When it is required to determine the Pythagorean triplets within a given range, a method is defined, that helps calculate the triplet values.
Below is the demonstration of the same −
def pythagorean_triplets(limits) : c, m = 0, 2 while c < limits : for n in range(1, m) : a = m * m - n * n b = 2 * m * n c = m * m + n * n if c > limits : break print(a, b, c) m = m + 1 upper_limit = 15 print("The upper limit is :") print(upper_limit) print("The Pythagorean triplets are :") pythagorean_triplets(upper_limit)
The upper limit is : 15 The Pythagorean triplets are : 3 4 5 8 6 10 5 12 13
A method is defined that defines variables to define values for each of the Pythagorean triplet.
Outside the method, the integer is defined.
This method is called by passing the integer.
The output is displayed on the console.
- Program to check if the given list has Pythagorean Triplets or not in Python
- Python program to print all even numbers in a range
- Python program to print all odd numbers in a range
- Program to find number of good triplets in Python
- Find all triplets in a list with given sum in Python
- Program to find all contiguously increasing numbers in start end range in Python
- C++ Program to find out the sum of shortest cost paths for all given triplets
- C# program to determine if a string has all unique characters
- Program to remove all nodes from BST which are not in range in Python
- Print all triplets with given sum in C++
- Find all triplets with zero sum in C++
- Program to determine the minimum cost to build a given string in python
- Python Program to Print all Numbers in a Range Divisible by a Given Number
- C++ program to convert all digits from the given range into words
- Program to determine if two strings are close in Python