My question code:
count = 0
for char in s:
if char.startswith("bob"):
count += 1
print ("Number of times bob occurs is: " + str(count))
I have a good solution as followed:
count = 0
for i in range(len(s)):
if s[i: i+3] == "bob"
count += 1
print ("Number of times bob occurs is: " + str(count))
My question: Instead of taking out a solution using integer "for i in range(len(s))", I want an alternative solution using character/string. Could anyone tell me why my above solution returns "0" in finding "bob"? Thanks.