I am getting an error on submitting the code for pythogoreans challenge, one error that i think might be of spaces in tuple value and comma ‘,’ , but i don’t know how to remove this extra space in tupples, please if you can check my code :
Code link :- https://drive.google.com/file/d/1ByoatcCVtTnQBN3xd2_tfDsz4PgKF52-/view?usp=sharing
Error in Pythagorean challenge
Hey @saksham_thukral
The code is not following the required output format. Try modifying your print statements to rectify that. See this comparison between yours and the correct output format.


Notice the extra newlines and spaces.
I m also getting the same error
Can you suggest me some ways , that how can i improve this format in my code, as tupples by default give single space after printing one value
The thing is that you don’t need to print tuples. You can construct the output format through hard-coding also. Refer to the code below:
if((a**2 + b**2) == A):
print(f"({a},{b})", end=' ')
My problem of printing was solved, but still my test case1 was failing because of Time limit exceed error, so for that i changed my code now, as in following link , but now , my test-case1 is working fine ie i am not getting TLE error but now my test case 2 is failing, don’t know why? please if you can check my code…
code link:- https://drive.google.com/file/d/1YCKnM3EQDr_70dLx3JeJgSOiqW2IOQ3W/view?usp=sharing
Hey @saksham_thukral
Your code was not printing anything for the case A==0, hence, the wrong answer.
Here’s the working code:
import math
t = int(input())
for _ in range(t):
A = int(input())
if (A==0):
print("(0,0)")
continue
for a in range(0, int(math.sqrt(A))):
b = math.sqrt(A-(a**2))
if ((b-math.floor(b))==0) and a<=math.floor(b):
b = math.floor(b)
print(f"({a},{b})", end=' ')
print()