pythagoras triplets
a pythagoras 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 pythagoras triplets R that can be formed (such that a<b<c)
for L = 20 pythagoras triplets satisfying the condition a<b<c
(3,4,5),(6,8,10),(5,12,13),(9,12,15),(8,15,17),(12,16,20).
hence output is 6
1) input is 5
output is 1
2) input is 20
output is 6
L = int(input('Enter limit: '))
count = 0
for i in range(1, L - 1):
for j in range(i + 1, L):
for k in range(j + 1, L + 1):
if i ** 2 + j ** 2 == k ** 2:
count += 1
print(count)
Comments
Leave a comment