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)