Python method for calculating palindrome numbers

Source: Internet
Author: User
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.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.