Python Forum

Full Version: simple problem
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hey guys I've got a simple problem but it's so frustrating
I am trying to write a code to print all "bob" in this string and print the count at the end .

s = 'bobazcebobgghabobkl'
count = 0
for i in s :
    y = s.find(i)
    if i == "b":
        count = count + 1 
        print(s[y :y + 3])
print(count)
and i except to get an output:
Output:
bob bob bob 3


but I already got:
Output:
bob bob bob bob bob bob 6


what's the wrong in my simple code
this question has been answered previously. use search for bob