Skip to content

Instantly share code, notes, and snippets.

@sunilk-n
Last active October 22, 2017 17:05
Show Gist options
  • Save sunilk-n/592f6000239e97be2b885733664f2571 to your computer and use it in GitHub Desktop.
Save sunilk-n/592f6000239e97be2b885733664f2571 to your computer and use it in GitHub Desktop.
Write a program that prints number of times the word "bob" occurs in a string. For example if s = "azcbobobegghakl" Then your program should print ,"Number of times 'bob' occurs is:2"
s = "azcbobobegghakl"
check = "bob"
checker = 0
for i in range(len(s)):
try:
if s[i] == check[0] and s[i+1] == check[1] and s[i+2] == check[2]:
checker +=1
except:
pass
print "Number of times 'bob' occurs is: "+checker
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment