1

I am a Python newbies. I am struck with this quiz. It should use a while or for loop. Here is a quiz question:

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

This is my code.

count = 0
string = 'bob'
strings = s.find(string)

for i in s:
    if strings != -1:
    count = count + 1
print(count)

Thank you for your help!

0 Answers0