I am printing them in the form of lists of two elements but that doesn’t seem to be working.
https://ide.codingblocks.com/s/67859
In what format am I suppposed to return the pairs?
Hey Vaibhav, there are a few mistakes in your code
- run both the for loops till x+1 as the last no. is not included and we want to iterate till x.
- update your nested loop’s range, it should be from i to x+1 not 0 to x+1
- there is no need to use list just give a print statement in if check
- as your output should exactly match the given output format so your print statement should be
print("({0},{1})".format(i,j))
- You haven’t taken the no. of test cases as input so take no. of test cases also in input and run your whole code snippet for every test case.
I have your code snippet, you can refer this
x = int(input())
for i in range(0,x+1):
for j in range(i,x+1):
if i**2+j**2==x:
print("({0},{1})".format(i,j))
1 Like
Hey Vaibhav,
As you are not responding to this thread, I am marking your doubt as Resolved for now. Re-open it if required.
Please mark your doubts as resolved in your course’s “ Ask Doubt ” section, when your doubt is resolved.