#Python
'''
Count the number of times the substring 'bob' appears in string s
'''
s='
i=0
ocr=0
while(i<(len(s)-2)):
ocr+=s.count('bob',i,i+3)
i+=1
print "Number of times bob occurs is:", ocr
'''
Count the number of times the substring 'bob' appears in string s
'''
s='
azcbobobegghakl'
i=0
ocr=0
while(i<(len(s)-2)):
ocr+=s.count('bob',i,i+3)
i+=1
print "Number of times bob occurs is:", ocr
0 comments:
Post a Comment