A Pythagorean triplet is a set of three integers a, b, and c such that a2+ b2 = c2. In the given limit L, find the number of Pythagorean triplets R that can be formed (such that a < b < c).
For
L = 20, Pythagorean triples satisfying the condition a < b < c are (3, 4, 5), (6, 8, 10), (5, 12, 13), (9, 12, 15), (8, 15, 17), (12, 16, 20).Hence the output should be
6.
- Sign in
- How it works
- Examples
- Reviews
- Homework answers
- Blog
- Contact us
Submit
97.9%
Successfully Done
In September 2022
Question #292913
A pythagorean triplet is a set of three integers a, b and c such that a**2+b**2=c**2.in the given limit L, find the number of pythagorean triplets R that can be formed (such that a<b<c).
Expert's answer
L=int(input("Enter a limit: ")) count=0 for a in range(1,L-1): for b in range(a+1,L): for c in range(b+1,L+1): x=a*a y=b*b z=c*c if (x+y==z): count+=1 print(count)
Need a fast expert's response?
Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!
Learn more about our help with Assignments: Python
Comments
No comments. Be the first!
Leave a comment
Related Questions
- 1. given an integer N, write a program that prints the count of the total numbers of digits between 1 a
- 2. write a program to find the sum S of the series where S = x-x^3+x^5+..... upto N terms.
- 3. Inputs 5 5 Output Equal If the given number are equal print "Equal". In all other cases, p
- 4. given an integer number N as input. write a program to print the right-angled triangular pattern of
- 5. you are given two given numbers, A and B where 1<= A <=B, write a program to find the number o
- 6. 6. Create an array with whole numbers values from 0 to 10 and find what is the command to extract th
- 7. 1. Create a list named ‘myList’ that has the following elements: 10,20,30,’apple’, True, 8.1
LATEST TUTORIALS
New on Blog
Who Can Help Me with My Assignment
There are three certainties in this world: Death, Taxes and Homework Assignments. No matter where you study, and no matter…
How to Finish Assignments When You Can’t
Crunch time is coming, deadlines need to be met, essays need to be submitted, and tests should be studied for.…
How to Effectively Study for a Math Test
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
The services are exceptional! The prices are great!
#317368 on Feb 2022
This is a Python Program to determine all Pythagorean triplets till the upper limit. Problem Description
The program takes a upper limit and determines all Pythagorean triplets till the upper limit.
Problem Solution
1. Take in the upper limit and store it in a variable.
2. Using a while loop and for loop, compute the Pythagorean
triplets using the formula.
3. If the value of the c is greater than the upper limit or if any of the numbers is equal to 0, break from the loop.
4. Print all the three numbers of the Pythagorean triplets.
5. Exit.
Program/Source Code
Here is source code of the Python Program to determine all Pythagorean triplets till the upper limit. The program output is also shown below.
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
Program Explanation
1. User must enter the upper limit and store it
in a variable.
2. The while and for loop is used to find the value of the Pythagorean triplets using the formula.
3. If the value of a side is greater than the upper limit or if any of the side is 0, the loop is broken out of.
4. Then the triplets are printed.
Runtime Test Cases
Case 1: Enter upper limit:20 3 4 5 8 6 10 5 12 13 15 8 17 12 16 20 Case 2: Enter upper limit:35 3 4 5 8 6 10 5 12 13 15 8 17 12 16 20 7 24 25 24 10 26 21 20 29 16 30 34
Sanfoundry Global Education & Learning Series – Python Programs.
To practice all Python programs, here is complete set of 150+ Python Problems and Solutions.
Next Steps:
- Get Free Certificate of Merit in Python Programming
- Participate in Python Programming Certification Contest
- Become a Top Ranker in Python Programming
- Take Python Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.
Subscribe to his free Masterclasses at Youtube & technical discussions at Telegram SanfoundryClasses.