I\'m writing a function to replace every n-th letter from a string
def replaceN(str, n):
for i in range(len(str)):
n=str[i]
newStr=str.replace(
You've put your return within the loop so after the first iteration it returns the string without the rest of the string being replaced. The string should be returned once the loop has completely finished. Something like this should work:
def replaceN(str, n):
for i in range(len(str)):
n=str[i]
newStr=str.replace(n, "*")
return newStr