I make some code about shrinking string in recursive function.
when input string is over it returns output.
it shows right thing in function but it returns None, instead of answer
def rec_encyption(input, i, cnt, output):
if i + 1 == len(input):
print(output)
return output
elif input[i] == input[i + 1]:
rec_encyption(input, i + 1, cnt + 1, output)
else:
output = output + input[i] + str(cnt)
rec_encyption(input, i + 1, 1, output)
def do_rec_encyption(input):
n = rec_encyption(input + " ", 0, 1, "")
print(n)
return n
print(do_rec_encyption("aaabbcccccca"))
I run this code in VSCode and the result is this:
a3b2c6a1
None
None
which means rec_encyption
return None, instead of 'output'
I can't find why and how to fix this problem