sir but I have put this condition j>=i so my code is giving expected answers. i ran it on online gdb
Pythagoras quesn
Can you save your code here -https://ide.codingblocks.com/
And share the link of the saved ide so I can look into it
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.
import math
def pythagoras(a):
c=math.floor(math.sqrt(a))
l=[]
for i in range(0,c+1):
for j in range(0,c+1):
if(i2+j2==a and j>=i):
l.append((i,j))
for b in sorted(l):
print(b,end=" ")
print(" ")
num=int(input())
lst=[]
for k in range(0,num):
lst.append(int(input()))
for k in lst:
pythagoras(k)
The indentation in your code is not clear .
You can refer to the code given below to try to understand the problem.
def pythagorean(c):
# a**2 + b**2 = c
# b = sqrt ( c - a**2 )
# just check the condition if it is a is less than equal to b, so print a and b
for a in range(int(math.sqrt(c))+1):
b = math.sqrt(c - (a ** 2))
if b == int(b) and a <=int(b):
print("({},{})".format(a,int(b)), end=" ")
# t is no. of test cases
t = int(input())
arr = []
# append all the input values for t test cases
for _ in range(t):
n= int(input())
arr.append(n)
# print result for each input value of t test cases
for i in arr:
pythagorean(i)
print()