Last active
October 22, 2017 17:05
-
-
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"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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