Q:

For Loop to Count Letters in a Word

I'm just learning python and I came to a problem that required me to put a string as an input in my "count letters function."
The function is supposed to count how many "a"s are in a word given (specifically, a fruit inputed by the user). 
The final value is correct, but in my function, it lists me the programs "procedure" if you will by listing how many "a"s are at each index and adding everything that was before.
I just want one final value, not a list.
If I'm not too clear, here is my program and test it out for yourself to see what I mean, and maybe help me come to a solution?
def count_letters(a):
    count=0
    for char in a:
        if char == 'a':
            count+=1
        print count

a=raw_input("Name a fruit and I will tell you how many letters are in it." + '\n')
print count_letters(a)

A:

It seems like you don't understand the difference between print and return. What you are doing is printing every single occurrence in the loop, when what you want is the final value at the end. What you would have to do is keep the same code, except when the loop terminates, you want to return whatever value is at the end. So get rid of print count, and remove the indent. Then you must return count. You don't want to return in the loop, because this will return the first value of count after a single character is checked. 
Message me for further questions if you have any.

