def replaceChar(myString, oldChar, newChar):
# if myString has no characters left, return newString
if myString == '':
return newString
elif myString[0] == oldChar:
# then add newChar to newString
else:
# then add myString[0] to newString
# Chop the first character off of myString
myString = myString[1:]
# recurse
replaceChar(myString, oldChar, newChar)
Since strings are immutable, I can't add newChar or oldChar to newString. I can't make newString a list, because it will get overwritten with each recursive loop. I also can't define that list outside of the function because the rules state that everything must be inside the function. How can I add these characters to my new string?