def reverseaddlow high Executes the reverse and add algorit
def reverse_add(low, high):
\'\'\' Executes the reverse and add algorithm for 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 numbers 10, 11, .., 49, 50. Or, the user could be interested in a single number such as 89. In
this case, low and high are both 89.
\'\'\'
# Write the rest of your code here.
print(\'low:\', low)
print(\'high:\', high)
def main():
\'\'\' The program driver. \'\'\'
# set cmd to anything except quit()
cmd = \'\'
# process the user commands
cmd = input(\'> \')
while cmd != \'quit\':
i = 0
while i < len(cmd) and cmd[i] != \' \':
i += 1
if \' \' in cmd:
low = int(cmd[:i+1])
high = int(cmd[i+1:])
else:
low = int(cmd)
high = low
reverse_add(low, high)
cmd = input(\'> \')
main()
This is my program so far. I need help filling in the rest of it so the code matches exactly the output in the picture.
Solution
def do_it(low):
itr=0
while True:
a=low
new=0
j=1
while a!=0:
b = a % 10
new = (new *10) + b
a = a / 10
if(new == low):
break
else:
print j,\". \",low,\" + \",new,\" =\",low+new
low=new+low
itr=itr+1
return itr
def check_pal(low):
itr=0
while True:
a=low
new=0
while a!=0:
b = a % 10
new = (new *10) + b
a = a / 10
if(new == low):
break
else:
low=new+low
itr=itr+1
return itr
def reverse_add(low, high):
if (low == high):
a1=do_it(low)
if (a1==1):
print \"\ \",low,\": PAL(\",a1,\"step)\ \"
else:
print \"\ \",low,\": PAL(\",a1,\"steps)\ \"
else:
for i in range(low,high+1):
a1=check_pal(i)
if (a1==1):
print i,\": PAL(\",a1,\"step)\"
else:
print i,\": PAL(\",a1,\"steps)\"
reverse_add(190,190)
reverse_add(84,91)


