Python-100-Days/Day01-15/Day05/code/palindrome.py

21 lines
415 B
Python
Raw Normal View History

2018-03-02 00:09:06 +08:00
"""
判断输入的正整数是不是回文数
回文数是指将一个正整数从左往右排列和从右往左排列值一样的数
Version: 0.1
Author: 骆昊
Date: 2018-03-02
"""
num = int(input('请输入一个正整数: '))
temp = num
num2 = 0
while temp > 0:
2019-05-03 21:17:36 +08:00
num2 *= 10
num2 += temp % 10
temp //= 10
2018-03-02 00:09:06 +08:00
if num == num2:
2019-05-03 21:17:36 +08:00
print('%d是回文数' % num)
2018-03-02 00:09:06 +08:00
else:
2019-05-03 21:17:36 +08:00
print('%d不是回文数' % num)