problem009.py (597B)
1 # problemName = "Special Pythagorean triplet" 2 # problemNum = 9 3 # solutionBy = "FIGBERT" 4 # language = "Python" 5 # dateCompleted = "28/01/2020" 6 from math import sqrt 7 8 def triplet(a, b): 9 c = sqrt(a**2 + b**2) 10 if a + b + c == 1000: 11 return int(a*b*c) 12 return False 13 14 if __name__ == "__main__": 15 for (i, k) in [(a, b) for a in range(500) for b in range(500) if a < b]: 16 answer = triplet(i, k) 17 if answer: 18 print(( 19 "The product of abc, where:\n\ta < b < c,\n\ta2 + b2 = c2,\n" 20 f"\ta + b + c = 1000\nis {answer}" 21 ))