i am working on this python function, which should take three parameters: The first, called the content string, can be any string. The second, called the token, should be a string containing a single character which is to be replaced in the content string. The third, should denote the new character(s) that will be in the resulting string.
I have this so far :
def myReplace(aString, token, newToken):
cnt = 0
while(cnt < len(aString)):
if(aString[cnt] == token):
aString[cnt] == newToken
return aString[cnt]
cnt+=1
#print("Couldn't find "+token+" in "+aString)
return "can not find the token you are looking for in the String"
The function is suppose to return a new string with the token letter(s) replaced by the new characters,
>>> result = myReplace("Hello world!",'l','q')
>>> print(result)
Heqqo Worqd!
but it returns only one character.
>>> myReplace("hello world", 'l', 'g')
'h'
i tried removing the 'cnt' variable as well, but this would not help.
Note: I can not use the built-in replace() method for this question.
Any help will be appreciated, its just i tried working on it and nothing seems to be working anymore.