In: Computer Science
Please solve this problem with Python Language.
P#2. A Pythagorean triplet is a set of three natural numbers, a < b < c, for which a2 + b2 = c2 . For example, 32 + 42 = 52. And a + b + c = 3 + 4 + 5 = 12. There exists exactly two Pythagorean triplet for which a + b + c = 300. Find a, b, c.
Hints: Level-0 Algorithm:
1. Find the possible ranges of a and b for which a+b+c is around 300 (include the paper & pencil analysis at the end of your report)
2. Compute c for each combination of a and b
3. Verify if ?+?+?=300 and ?2+?2=?2 and ?<?<?
4. Print results
I really don't understand to do this problem.
PROGRAM: import math def pythagorean_triplet(n): #defining function to find all possible triplet for b in range(2,n): #starting value of b with 2 for a in range(1, b): #staring value of a with 1 so a<b c = math.sqrt(a * a + b * b) #find the value of c=(a^2+b^2)^(1/2) if c % 1 == 0 and a+b+c==n and a<b<c: #verify three conditions print(a, b, int(c)) pythagorean_triplet(300) PROGRAM SCREENSHOT: OUTPUT OF PROGRAM: