python - No result returned during recursion -


so creating simple recursive function compares 2 strings, 'string' , 'target', , if they're same, function replaces 'target' 'rep', function of find , replace see in text editor. issue is, function returns nothing. because hasn't hit base case or missing return somewhere? i'm still relatively new python bare me if made silly mistake.

def helperfn(string,target,rep,x): # x set 0     if x==len(string): #base case         target=rep         return target     if len(string)==len(target):         if string[x]==target[x]:             helperfn(string,target,rep,(x+1))     else:          return "string , target not same" 

a few examples of expected output should be:

helperfn("noway","noway","yes",0)=>"yes" helperfn("ok","ok","never",0)=>"never" 

when call function recursively, want return value.

return helperfn(string,target,rep,(x+1))


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -