- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- 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.
Kickstart Your Career
Get certified by completing the courseGet Started