Today we are going to share a Python program to determine all Pythagorean triplets in the range. If you are a python beginner and want to start learning the python programming, then keep your close attention in this tutorial as I am going to share a Python program to determine all Pythagorean triplets in the range with the output.
To increase your Python knowledge, practice all Python programs, here is a collection of 100+ Python problems with solutions.
Copy the below python program and execute it with the help of python compiler.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
limit=int(input("Enter upper limit:")) c=0 m=2 while(c<limit): for n in range(1,m+1): a=m*m-n*n b=2*m*n c=m*m+n*n if(c>limit): break if(a==0 or b==0 or c==0): break print(a,b,c) m=m+1 |
Enter upper limit:20
3 4 5
8 6 10
5 12 13
15 8 17
12 16 20
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.