Python includes exercises 30
Title: a 5-digit, determine if it is a palindrome. That 12321 is a palindrome, the same bits and ten thousand, ten and one thousand identical.
Program Analysis: None.
Source Code:
#!/usr/bin/python # -*- coding: UTF-8 -*- a = int(raw_input("请输入一个数字:\n")) x = str(a) flag = True for i in range(len(x)/2): if x[i] != x[-i - 1]: flag = False break if flag: print "%d 是一个回文数!" % a else: print "%d 不是一个回文数!" % a
The above example output is:
请输入一个数字: 12321 12321 是一个回文数!