Project Euler: Problem 9

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 [7]:
for a in range(1,1000): #iterates a 1-999
    for b in range(2,1000): #iterates b 2-999
        c=1000-a-b #sets the condition where c is the difference of 1000, a, and b
        if c>0: #we are looking for numbers above 0 since a and b are both above 0
            if a**2+b**2==c**2: #prints product if the condition is true
                print(a*b*c)


31875000
31875000

In [ ]:
# This cell will be used for grading, leave it at the end of the notebook.