如何用Python编写一个判断回文数
1个回答
2016-07-04
展开全部
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
def ishuiweinum(num):
if not isinstance(num,int):
return False
if num<0:
return False
numlist=[]
while num>0:
numlist.append(num%10)
num/=10
reverselist=numlist[:]
reverselist.reverse()
return reverselist==numlist
if __name__=='__main__':
print(ishuiweinum(12345))
print(ishuiweinum(1234321))
2
3
4
5
6
7
8
9
10
11
12
13
14
15
def ishuiweinum(num):
if not isinstance(num,int):
return False
if num<0:
return False
numlist=[]
while num>0:
numlist.append(num%10)
num/=10
reverselist=numlist[:]
reverselist.reverse()
return reverselist==numlist
if __name__=='__main__':
print(ishuiweinum(12345))
print(ishuiweinum(1234321))
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询