I am trying to build a function(which uses function recursion) that scans a number, n, to look for a digit d, & if found, I would like to replace d with a specified number r, as shown in the code below. This code works fine but the output is in a string format. I have tried numerous ways to change it to output an integer but to no avail. Thanks for the help!
def replace_digit(n, d, r):
number = str(n)
i = 0
if len(number) == 1:
if number == str(d):
return str(r)
else:
return number
else:
if number[i] == str(d):
return number[:i] + str(r) + replace_digit(int(number[i+1:]),d,r)
else:
return number[i] + replace_digit(int(number[i+1:]),d ,r)
int()