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 [1]:
# YOUR CODE HERE
from math import sqrt

a = 0
b = 0
lisp = []

while a != 500:
    a += 1
    c =sqrt(a**2 + b**2)
    d = a + b + c
    if a**2 + b**2 == c**2 and d == 1000:
        print(a,b,c)
        print(a*b*c)
    elif a >= b:
        b += 1
        a = 0


200 375 425.0
31875000.0

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