I am beginner in programming, So can you please tell me what's wrong with my code?
I want to print next palindrome number if the number entered by the user (n) is not palindrome
n = int(input("Enter any number :- "))
reverse = 0
temp = n
while (n!=0):
reverse = reverse * 10
reverse = reverse + n%10
n=n//10
if(temp==reverse):
print ("Already palindrome:: ")
if(temp != reverse):
new_temp = temp
new_reverse = 0
for i in range(new_temp,new_temp+10):
while(temp != 0):
new_reverse = new_reverse * 10
new_reverse = new_reverse + temp%10
temp = temp//10
if(new_temp==new_reverse):
print ("Next pallindrome is :- ",new_temp)
break
if(new_temp != new_reverse):
temp = new_temp+1
if a definite range is given:-
funcion to check if the number is a palindrome
putting up range from the next number till 15 digits
I have written this for finding next pallindrome number given a pallindrome number..
# similarly for this problem take the left part of given number ...reverse it..store it in temp
**
**
To check if a number is a palindrome, you don't need to convert it to a number. In fact, its a lot simpler if you just check the string equivalent of your number.
Use this to your advantage, and create a function:
Next, to find the next palindrome, simply increment the number till your palindrome check is true.
Combine all that, and you have:
Here is how it works: