Question #113924

10. Adding certain numbers to their reversals sometimes produces a palindromic number. For

instance, 241 + 142 = 383. Sometimes, we have to repeat the process. For instance, 84 + 48 =

132 and 132 + 231 = 363. Write a program that finds both two-digit numbers for which this

process must be repeated more than 20 times to obtain a palindromic number.

Expert's answer

def process(max_tries=1000):
    for a in range(11, 100):
        x = a
        for n in range(max_tries):
            x = x + int(str(x)[::-1])
            if str(x) == str(x)[::-1]:  # stackoverflow.com/questions/17331290
                if (n > 20):  # 89 23, 98 23
                    print(a, n)
                break

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS