A Pythagorean Triplets is a set of three integers a, b, 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).
The following set of codes should print the number of Pythagorean triplets in a given limit L:
# Pythagorean triplets
# Prompt the user to enter a limit of choice
L = int(input("Provide a limit: "))
# Initialize the counter for the possible Pythagorean triplets
counter = 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**2
y = b**2
z = c**2
if x + y == z:
counter += 1
print(counter)
Comments
Leave a comment