我需要检查一个数字是否是 Lychrel 数字,如果不打印循环直到它到达回文的次数,由于某种原因它总是打印 0
num = input('please enter your number ')
num = int(num)
count = 0
for i in range(1, 500):
if str(num) == str(num)[::-1]:
print(count)
exit()
else:
num = num + int(str(num)[::-1])
count += 1
print('True')
更新:感谢 Vova,代码现在可以正常工作。固定代码:
num = int(input('please enter your number '))
count = 0
for i in range(1, 500):
if str(num) == str(num)[::-1]:
print(count)
exit()
else:
num = num + int(str(num)[::-1])
count += 1
print('True')