Started learning python a couple weeks back. Wrote a python program to count the number of times the sequence 'bob' appears in a string s:
s=input('Enter String')
a=0
b=1
c=2
count=0
for var in s:
if(s[a]=='b' and s[b]=='o' and s[c]=='b'):
count+=1
if (c<(len(s)-1)):
a+=1
b+=1
c+=1
print(count)
The output shows up properly for strings like 'bobbooboboooblobobbobbc'. But, for strings like 'nqsbobobdbtobob', I'm getting output count two more than the actual count of number of occurrences of 'bob'. Can someone please tell me what the cause might be?