https://projecteuler.net/problem=9
A Pythagorean triplet is a set of three natural numbers, $a < b < c$, for which,
$$a^2 + b^2 = c^2$$For example, $3^2 + 4^2 = 9 + 16 = 25 = 5^2$.
There exists exactly one Pythagorean triplet for which $a + b + c = 1000$. Find the product abc.
In [1]:
# YOUR CODE HERE
def Pyth_Trip(x):
#since c>b>a, the limits on b and a can be restricted
for c in range(0,x):
for b in range(0,c):
for a in range(0,b):
if a + b + c == x:
if a**2 + b**2 == c**2:
return [a, b, c, a*b*c]
This program takes a few seconds to run
In [2]:
print(Pyth_Trip(1000))
In [ ]:
# This cell will be used for grading, leave it at the end of the notebook.