That program should print the number of times the string "bob" occurs in a string, for example: if s = "azcbobobegghakl", then the program should print 2. it works in some cases but other times it doesn't count correctly. What seems to be the problem?
numbob = 0
i = 0
if len(s) > 2:
for letter in s:
if letter == "b":
if len(s) < 3:
break
i = s.index(letter)
s = s[i: ]
if s[0] == "b" and s[1] == "o" and s[2] == "b":
numbob += 1
s = s[2: ]
else:
s = s[i+1: ]
print(numbob)