Your return
is in your for loop! Be careful with indentation, you want the line return count
to be outside the loop. Because the for loop goes through all characters in word
, the outer while loop is completely unneeded.
A cleaned-up version:
def count_letters(word, to_find):
count = 0
for char in word:
if char == to_find:
count += 1
return count