接受一个数字作为输入并检查给定的数字是否为回文 如果是回文数,则在屏幕上打印该数字 如果它不是回文数字,则反转该数字并将其添加到先前的数字重复此操作直到获得回文数字并将该回文数字打印在屏幕上
输入:127
输出:848
如果有人能解决这个问题,我将不胜感激:
n = int(input())
if str(n) == str(n)[::-1]:
print(str(n)[::-1],"is a palindrome")
else:
else条件下应该怎么写
最佳答案
这对我有用:
n = int(input())
while True :
if str(n) == str(n)[::-1]:
print(str(n)[::-1],"is a palindrome")
break
else:
n += int(str(n)[::-1])
关于python - 在python中添加反转的前一个数字来实现回文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62066873/