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 [31]:
# YOUR CODE HERE
def is_sum(a,b,c):
    if a+b+c==1000:
        print ("tru")
        return 1
    else:
        print ("nah")
        return 0

In [36]:
import math
a= int(input("First number: "))
b= int(input("Second number: "))
c= int(input("Third number: "))
def pythag(a,b):
    c=math.sqrt(a**2+b**2)
    return c
    print (c)
    
is_sum(a,b,c)


First number1
Second number2
Third number3
nah
Out[36]:
0

In [1]:
import math
x=1
y=1

while x < 1000:
    while y < 1000:
        c=math.sqrt(x**2+y**2)
        if x+y+c==1000.0:
            print("The three numbers are: ")
            print("a=%s b=%s c=%s"%(x,y,c))
            d=x*y*c
            print ('a*b*c=%s'%(d))
            x=1001
            y=1001
        y=y+1
    y=1
    x=x+1


The three numbers are: 
a=200 b=375 c=425.0
a*b*c=31875000.0

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