Question: Using python, . Below is the beginning of the program and the functions. Reversing and adding numbers. You will write a Python program (called q2.py)
. Below is the beginning of the program and the functions.
Reversing and adding numbers. You will write a Python program (called q2.py) to implement the following procedure to produce palindromic numbers. a) Take any positive integer r. If r is a palindrome, stop. Otherwise, continue to step (b) b) Reverse the digits of r. c) Add the reverse to r. d) If the sum is a palindrome, then stop. Otherwise, let r represent the sum, and repeat steps (b) through (d) Steps (b) through (d) represent a single iteration. Below: are the number of iterations required for a few numbers to become palindromic using the reverse and add procedure. 8 is a palindrome. It is palindromic after 0 iterations 56 becomes palindromic after 1 iteration: 56 65 121 57 becomes palindromic after 2 iterations: 57 75 132, 132 t 231 363 59 becomes palindromic after 3 iterations: 59 95 154, 154 451 605, 605 506 1111. 89 takes an unusually large 24 iterations (the most of any number under 10,000 that is known to resolve into a palindrome) to reach the palindrome 8813200023188 For 196, it is not known if the above procedure leads to a palindromic number Your program will consist of two user-defined functions reverse-add (low, high) and main The reverse add() function implements the reverse and add numbers procedure described above for all integers in the range low to high. For example, if low is 10 and high is 50, then the function would run the reverse and add procedure on the 49, and 50. or, the user could be interested in a single number numbers 10, 11, such as 89. In this case, low and high are both 89 For each number in the range of interest, your function will either output the number of steps required for it be palindromic or report that it does not lead to a palindrome within 100 steps. If the low and high range includes a single number (i.e., 190 to 190)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
