Counting bobs
Assume s is a string of lower case characters.
Write a program that prints the number of times the string 'bob' occurs in s. For example, if s = 'azcbobobegghakl', then your program should print
Number of times bob occurs is: 2
s='azcbobobegghakl'
count = 0
while s:
position = s.find('bob')
if position!=-1:
count+=1
else:
break
s=s[position+1:]
print 'Number of times bob occurs is: '+str(count) 
查看5道真题和解析