Open
0

# The question is to print all the Pythagorean triplet from a accepted range.I am getting repetitive values ex:3,4 and 4,3.

import math a=int(input("start range")) b=int(input("end range")) for c in range(a,b+1): for d in range(a,b+1): for l in range(a,b+1): p=c**2+d**2 if l==math.sqrt(p): print (c,d,l) this is the code I wrote. I am getting the answer but I get repetative values ex3,4 ,5and 4,3,5. I only need 3,4,5 or 4,3,5 .how to I print without repetition. please just correct my mistake I don't want a new logic to solve this problem. I am relatively new to Python

2nd Oct 2018, 4:45 PM
Mara
+ 1
thanks a lot for the answers
3rd Oct 2018, 12:48 PM
Mara
0
Hi shivaani! As per your request, here's the smallest amount of change that'd fix your code: Modify line 5 to for d in range(c,b+1): This ensures that the second number in the Pythagorean triplet is no less than the first, thus removing duplicates. Hope that helps ðŸ˜Š
2nd Oct 2018, 5:30 PM
Kishalaya Saha
0
Jay Matthews, the OP didn't want a different algorithm.
3rd Oct 2018, 1:44 AM
Kishalaya Saha
0
here's it, ask if you have any questionðŸ˜ƒ https://code.sololearn.com/caTIqKpqdXSR
3rd Oct 2018, 4:37 AM
Flandre Scarlet