方法一:
target=input('please input a number with five digit:')
if target[0]==target[4] and target[1]==target[3]: print('it is a huiwenshu')
else: print('it is not a huiwenshu')
#一个5位数,判断它是不是回文数。即12321是回文数,个位与万位相同,十位与千位相同。
target=input('please input a number with five digit:')
if target[0]==target[4] and target[1]==target[3]: print('it is a huiwenshu')
else: print('it is not a huiwenshu')
方法二:
target=int(input('pleasr intput a number with five digits:'))
digits=[]
while target>=1:
digits.append(target%10)
target=int(target/10)
if digits[4]==digits[0] and digits[3]==digits[1]: print('it is huiwenshu')
else : print('it is not huiwenshu')
#一个5位数,判断它是不是回文数。即12321是回文数,个位与万位相同,十位与千位相同。
target=int(input('pleasr intput a number with five digits:'))
digits=[]
while target>=1:
digits.append(target%10)
target=int(target/10)
if digits[4]==digits[0] and digits[3]==digits[1]: print('it is huiwenshu')
else : print('it is not huiwenshu')
本文介绍两种方法来判断一个输入的五位数是否为回文数。第一种方法直接比较字符串形式的数字;第二种方法则通过分解数字并比较各位数字。

被折叠的 条评论
为什么被折叠?



