Demlo number with Python
Demlo numbers are sequence of palindromic numbers 1, 121, 12321, 1234321, 123454321..... to nth terms.
They can be generated in the following manner (without the use of math libraries)...
When observed carefully, the numbers are found to be generated in following way:
1*1, 11*11, 111*111, 1111*1111, ......
Accordingly, python can generate the series in following manner:
for i in range(1,int(input())+1):
print(int("1"*i)*int("1"*i))
But the above solution, though correct, uses str to int conversion which can be avoided with a pure int based approach (mathematical generator function):
for i in range(1,int(input())+1): print((10**i-1)**2//81)
Comments