Answer to Question #218169 in Python for kaavya

Question #218169

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.


1
Expert's answer
2021-07-17T10:41:48-0400
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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS