Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help writing a Pythagorean Triples python 3 algorithm. Cant use *any* for

ID: 3669022 • Letter: I

Question

I need help writing a Pythagorean Triples python 3 algorithm. Cant use *any* for loops! Only use while loops. Also, dont use floating point arithmetic. Has to be just like the instructions listed below.

Instructions:

Write a Python program that will output all of the pythogorean triples in a specified interval. A pythogorean triple, (a,b,c) consists of three integers a < b < c such that the sum of the squares of the two smaller integers is equal to the square of the largest. Your program will input an integer value n > 10 from the user (keyboard input) and, using a series of nested while loops, determine and print out all the pythagorean triples with hypotenuse values ( length c ) in the closed interval [1, n] (one triple per line).

You also need to add a validate/retry loop to insure that the user enters an acceptable upper bound value. Allow the user 3 tries before giving up.

Explanation / Answer

def triples(n):
   for c in range(1,n+1):
       for a in range(1,c):
           for b in range(a,c):
               if (a*a + b*b) == (c*c):
                   print (c)