I was trying to write a function encodeM
which basically takes a string s
and integer move
which shifts the ascii value of a character. I tried writing the funtion the normal way which I think works properly. Is there a way I can write the same function with recursion? I have provided the code for the function with normal way:
def encodeM(s,move):
newStr=""
for char in message:
num=ord(char)
if char.isalpha():
num+=move
if char.isupper():
if num>ord("Z"):
num-= 26
elif num<ord("A"):
num+= 26
elif char.islower():
if num>ord("z"):
num-= 26
elif num<ord("a"):
num+=26
newStr+=chr(num)
else:
newStr+=char
return newStr