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.
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)
Comments
Leave a comment