I'm not sure why I'm getting an
IndexError: string index out of range
with this code.
s = 'oobbobobo'
a = 0
for b in range(len(s)-1):
if (s[b] == 'b') and (s[b+1] == 'o') and (s[b+2] == s[b]):
a += 1
elif (s[b] == 'b') and (s[b+1] == 'o') and None:
break
print("Number of times bob occurs is: ", a)
I thought the elif statement would fix the error, so I'm lost.
forloop termination condition is wrong, it should be:for b in range(len(s)-3):