123321 is a very special number. Reading it from the left is the same as reading it from the right. Enter a positive integer n, and program to find all such five-digit and six-digit decimal numbers, satisfying that the sum of the digits is equal to n

a=int(input())
for i in range(1,10):
    for j in range(10):
        for k in range(10):
            if i*2+j*2+k==a:
                print(i*10000+j*1000+k*100+j*10+i)
for i in range(1,10):
    for j in range(10):
        for k in range(10):
            if i*2+j*2+k*2==a:
                print(i * 100000 + j * 10000 + k * 1000+k*100 + j * 10 + i)

The reason is very simple, you should be able to understand the baby who does not understand, leave a message and ask.

Guess you like

Origin blog.csdn.net/jiahuiandxuehui/article/details/115198732