Created
September 19, 2013 07:55
-
-
Save sosoyososo/6620318 to your computer and use it in GitHub Desktop.
python:回文数字判断
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
i = 1281854581821 | |
def getMax(num): | |
if num < 10: | |
return num | |
return getMax(num/10) | |
def isLastEqualFirst (num) : | |
if num < 10 : | |
return YES | |
return num%10 == getMax(num) | |
def getNumWhioutFisrt(num): | |
if num <= 10: | |
return 0 | |
return num%10 + getNumWhioutFisrt(num/10)*10 | |
def getNumWhioutFirstAndLast(num): | |
num = getNumWhioutFisrt(num) | |
return num / 10 | |
def isPalindrome(num): | |
while num > 10: | |
if isLastEqualFirst(num): | |
num = getNumWhioutFirstAndLast(num) | |
else: | |
return False | |
return True | |
print(isPalindrome(i)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment