I am trying to make a program that searches a string for 'bob' and prints the amount of times it appears. Here is the code:
s = 'mbobobboobooboo'
numbob = 0
for i in range(len(s) ) :
u = s[i]
if u == 'o':
g = i
if g != 0 and g != len(s) :
if (s[g+1]) == 'b' and (s[g-1]) == 'b': #this line is the problam
numbob += 1
print("Number of times bob occurs is: " +str(numbob) )
I am getting the string index out of range error and i cant seem to fix it. any suggestions