Bob Counter in Python

后端 未结 8 1323
名媛妹妹
名媛妹妹 2021-01-28 11:25

Using Python 2.7, I was attempting to count the number of occurances of \'bob\' in the phrase \'bobbbobobboobobookobobbobbboj.\' To do this, I wrote the code below:



        
8条回答
  •  终归单人心
    2021-01-28 11:38

    s = ('bobobobobobob')
    count = 0
    
    for i in range(len(s)):
        if s[i:i+3] == "bob":
            count += 1
    
    print ('Number of times bob occurs is: ' + str(count))
    

提交回复
热议问题