Hello all,

I am trying to write a program for a programming class that finds the
number of a specific string (bob) in a string of characters. I am using one
of the sample strings they give me and it should find 2 instances of bob
but my script returns 0. Since they want it to find 2 from the bobob in the
string using "bob in s" doesn't work (it only returns 1). My eyes are
crossing looking at the code, can someone give me a hint on what I am
missing that causes this to not give me the correct answer of 2.

#!/usr/bin/env python3

s = 'azcbobobegghakl'

count = 0
theo = False
firstb = False

for i in s:
    if i == 'b':
        firstb == True
    if (i == 'b') and (theo == True):
        count += 1
    if (i =='o') and (firstb == True):
        theo = True
    if (i != 'b') and (i != 'o'):
        theo = False
        firstb = False


print(count)

Thanks,
Pat
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to