1
def find_triplet(total):
3
(int) -> list of list of ints
5
Returns the list of ints that are pythagorean triplets and whose sum
11
c = total - 2 #highest possible value of c
13
b = total - (c + a) #the sum will always be total
14
n = total // 3 #save yourself from doing the same calculation hundreds of times
15
triples = [] #a place to store the triples
17
while(c >= n): #c must be greater than both a and b
18
while(b >= a): #a will always be higher in this algorithm
19
if(a**2 + b**2 == c**2): #test for pythagorean triples
32
(list of list of ints) -> list of ints
34
Returns a list of the products of each list of ints
36
>>>multiples([[3, 4, 5]])
49
if __name__ == '__main__':
50
print("You are looking for the products of pythagorean triples whose sum is P.\n")
51
target = input("What value would you like to use for P?")
52
answer = multiples(find_triplet(target))
53
print("The products of pythagorean triples whose sum is {0} is {1}.\n".format(target, answer))