I am trying to write a function which prints the minimum number of steps involved to make starting number to target number with multiply by 2 and subtract by 1.
However, I am getting the error:
RecursionError: maximum recursion depth exceeded in comparison
Here's the code I've written:
def no_steps(start,target,sofar):
if start == target:
return sofar
elif start < target and start > 0:
no_steps(start*2,target,sofar+'*2 ')
no_steps(start-1,target,sofar+'-1 ')
print(no_steps(2,6,''))
May I know what am I doing wrong and is there any issue with the code?