Python IndexError: string index out of range
<p>Can someone help me why is it saying: "IndexError: string index out of range"
When I add the "letterCount += 1" to the first else it makes this error, without it is working.</p>

<p>The goal is to count "bob"s in s.</p>

<p>Thanks!</p>

<pre><code>s = 'oobobodobooobobobobabobbobbobobbobbobhbxbobbk'

vowelCount = 0
letterCount = 0
pointer = s

for pointer in s:  
    print(pointer)
    if pointer == 'b':
        print (str(letterCount) + '. betÅ± B' )

        if (s[letterCount+1] + s[letterCount+2]) == str('ob') :
           vowelCount += 1
           letterCount += 1
           print( str(vowelCount) + '. BOB megtalÃ¡lva')
        else:
           print('Nem OB jÃ¶n utÃ¡na')
           letterCount += 1
    else:      
        print(str(letterCount) + '. betÅ± nem B')
        letterCount += 1

print ("Number of times bob occurs is: " + str(vowelCount))
</code></pre>

<pre><code>The final solution.

s = 'obbobbbocbobbogboobm'

vowelCount = 0
letterCount = 0
pointer = s

for pointer in s:  
    print(pointer)
    if pointer == 'b':
        print (str(letterCount) + '. betÅ± B' )

        if (len(s)-2 &gt; letterCount):      
            print('van utÃ¡na kÃ©t betÅ±')
            if (s[letterCount+1] + s[letterCount+2]) == str('ob') :
               vowelCount += 1
               letterCount += 1
               print( str(vowelCount) + '. BOB megtalÃ¡lva')
            else:
               print('Nem OB jÃ¶n utÃ¡na')
               letterCount += 1
        else:
           print('nincs utÃ¡na kÃ©t betÅ±')           
           break
    else:      
        print(str(letterCount) + '. betÅ± nem B')
        letterCount += 1

print ("Number of times bob occurs is: " + str(vowelCount))
</code></pre>

python