Answer to Question #260260 in Python for anji

Question #260260

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



1
Expert's answer
2021-11-02T17:35:40-0400
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)

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