Count letters in a word in python debug

Johnny picture Johnny · Dec 30, 2010 · Viewed 34k times · Source

I am trying to count the number of times 'e' appears in a word.

def has_no_e(word):     #counts 'e's in a word
    letters = len(word)
    count = 0
    while letters >= 0:
        if word[letters-1] == 'e':
            count = count + 1
        letters = letters - 1
    print count

It seems to work fine except when the word ends with an 'e'. It will count that 'e' twice. I have no idea why. Any help?

I know my code may be sloppy, I'm a beginner! I'm just trying to figure out the logic behind what's happening.

Answer

user225312 picture user225312 · Dec 30, 2010
>>> word = 'eeeooooohoooooeee'
>>> word.count('e')
6

Why not this?