Answer to Question #113924 in Python for Yumiko

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.
1
Expert's answer
2020-05-05T03:47:53-0400
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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS