In this paper, we describe Python's method of calculating palindrome number. Share to everyone for your reference. Specific as follows:
Here to check whether the number is a palindrome number, with 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 are some trickery :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 the specified number with 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 reversed number :p Aram Num: : return:" "" temp = "%d"%num; str = temp[::-1]; return int (temp) + int (str);p rint (Create_palindrome (num));
Hopefully this article will help you with Python programming.