Here is the task . Given a string. Remove from it all the characters whose indices are divided by 3. The characters of the string are numbered starting from zero.
Here is the code.
s = str(input()) pos = 0 v = 0 while v != -1: v = s.find('', pos) k = s[v] if v % 3 == 0: s = s.replace(k, '') pos += 1 print(s) Here is a mistake.
k = s[v]. IndexError: string index out of range.
Explain, please, what is wrong with the code?
s = ''.join(x for i,x in enumerate(s) if i%3);) - MaxUprint(v, repr(s))before the problem line - andreymal