This article illustrates the method of calculating palindrome numbers in Python. Share to everyone for your reference. Specifically as follows:
Here to check the number is not palindrome number, using the 196 algorithm to generate a number of palindrome number
num = 905;
def is_palindrome (num): "" "
to determine whether a number is a palindrome number, here is a bit tricky
:p Aram Num:: Return:" "" ""
:p Aram Num:: Return: "" "
" "
temp ="%d "%num;
str = temp[::-1];
if temp = = str: return
True;
else: return
False;
def create_palindrome (num): "" "
calculates the palindrome number of a specified number by using the 196 algorithm
:p Aram Num:: Return:" ""
"
count = 0;
While true:
if True = = Is_palindrome (num):
output = "This is a palindrome number:%d"%num + "\ r \ n Total number of%d"%count;
print (output);
break;
else:
num = Add (num);
Count + 1;
def add (num): "" "
num is added to its own descending number
:p Aram Num:: Return:" "" ""
temp = "%d"%num;
str = temp[::-1];
return int (temp) + int (str);
Print (Create_palindrome (num));
I hope this article will help you with your Python programming.