0
Program on kaprekar number.
A number say 45 when squared gives 2025, so 20+25 gives 45. But my program gives me "Time limit exceeded". Can somebody tell me what am i doing wrong. Learning python new. https://code.sololearn.com/c2NTNAnpEFM8/?ref=app
10 Respostas
+ 4
The while loop is infinite. The condition n!=0 is always true because n never decreases.
+ 2
Nice code Sagnik, where did you get the formula for unique number? the one I found online has different specification here:
http://www.guideforschool.com/203266-java-program-to-check-for-unique-number/
And why you check elif n%10 < 0? are you accepting negative numbers?
+ 2
Sagnik no problem, good job you fix the problem. Can kaprekar number program accept negative input? please explain the elif n%10 < 0 because I don't understand ...
+ 2
Sagnik Majumder2
Good job!
We can simplify it like this ...
n1 = count // 2
if count % 2 != 0:
n1 += 1
This way we don't need an else block at bottom ...
Please edit the forum question, so not confuse people, it still says "Program on unique number." đ
+ 2
Sagnik I made a mistake up there in code sample, but now it's fine, I changed it, just letting you know ... đ
+ 1
Thankx i have made the required changesđ
+ 1
Sry my bad, its kaprekar number. Thanks đ
+ 1
Actually i am using the while loop to find the length of the number, so the if statement counts the number to till the last digit. I have used the elif statement to increase the count by 1 for the last(first) digit.
+ 1
It seems my code dont work for numbers like 297
+ 1
Yeah i removed thatđ