Here is the code:
def upper_every_nth (s, n):
i = 0
while len (s) > (i * (0 + n)) :
character = s[i * (0 + n)]
s = s.replace(character, character.upper(), 1)
i = i + 1
return (s)
I want it to return a string that is identical to s except that every nth character (starting at position 0) is uppercase.
>>> upper_every_nth("cat", 2)
'CaT'
>>> upper_every_nth("hat", 3)
'Hat'
The problem is I cannot use the.replace method since it replaces all the occurrences of that letter in a string if not, only the first occurrence.
So let's say the string is 'deer'. I want to convert the second occurrence of 'e' to upper case. But with .replace method, it is either I get 'dEEr' or 'dEer'.