How to calculate palindrome numbers in Python _python

Source: Internet
Author: User
Tags in python

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.

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.