I do not know how to check if this is working properly.
def find_pythagorean_triples(max_hypotenuse):
triples = []
for a in range(1, max_hypotenuse):
for b in range(a, max_hypotenuse):
c = (a**2 + b**2) ** 0.5
if c.is_integer() and c < max_hypotenuse:
triples.append((a, b, int(c)))
return triples
try:
max_hypotenuse = int(input("Enter the maximum hypotenuse value: "))
if max_hypotenuse <= 0:
raise ValueError("The maximum hypotenuse must be a positive integer.")
triples = find_pythagorean_triples(max_hypotenuse)
for triple in triples:
print(triple)
except ValueError as e:
print(f"Invalid input: {e}")
def gcd(x, y):
while y:
x, y = y, x % y
return x
def is_primitive(triple):
a, b, c = triple
return gcd(gcd(a, b), c) == 1
primitive_triples = [triple for triple in triples if is_primitive(triple)]
for triple in primitive_triples:
print(triple)
print("Primitive Pythagorean triples with hypotenuse less than 300:")
print(primitive_triples)