I am a complete noob to programming so excuse the ignorance. I am taking a MOOC and can't for the life of me figure out what steps to take to solve this problem:
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
OK. I know that a for loop is necessary. I think it should start with:
x=bob
count=0
for count in range(s):
>if
Here I am not sure how to retrieve the specific word 'bob' from the index, and I know I need to enter count+=1 but am not sure where. Could someone please help me? I am sure I could solve this on myself but I am getting frustrated after a few hours!
ll needrange(len(s))` instead ofrange(s), sincesis not an integer. Then, usex == s[count : count+len(x)].s, how do you know that the word inxhas started? Now that you know it's started, how do you know it has ended?for x in range(len(s)): >x==s[count:count+lensx)]