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 [34]:
# assign a from 1-1000
for number_a in range(1,1000):
    #assign b from a-1000
    for number_b in range(number_a, 1000-number_a):
        #assign b and c according to a
        number_c = 1000 - number_a - number_b
        number_b = 1000 - number_a - number_c
        #if numbers meet the pythagorean theorem, then print the product
        if (number_a**2) + (number_b**2) == (number_c**2):
            print (number_a*number_b*number_c)


31875000

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