使用Python,反转一个整数,并告诉回文 [英] Using Python, reverse an integer, and tell if palindrome
本文介绍了使用Python,反转一个整数,并告诉回文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用Python,反转整数并确定它是否是回文。这是我对反转和回文的定义。我有一个正确的逻辑吗?
pre $ def c
s = len(num)
newnum = [无] *长度
我为数:
s = s-1
newnum [s] = i
返回newnum
def回文(num):
a = str(num)
l = len(z)/ 2
如果a [:1] == a [-1:] [:: - 1]:
b = True
else:
b = False
麻烦写 def main
。
解决方案
def palindrome(num):
return str(num)== str(num)[:: - 1]
Using Python, reverse an integer and determine if it is a palindrome. Here is my definition of reverse and palindrome. Do I have a correct logic?
def reverse(num):
s=len(num)
newnum=[None]*length
for i in num:
s=s-1
newnum[s]=i
return newnum
def palindrome(num):
a=str(num)
l=len(z)/2
if a[:1]==a[-1:][::-1]:
b=True
else:
b=False
I am having some trouble to write def main
.
解决方案
def palindrome(num):
return str(num) == str(num)[::-1]
这篇关于使用Python,反转一个整数,并告诉回文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文