As already mentioned, you can implement the test with a simple one word.count('e'). If you do not do this as a simple exercise, it is much better than trying to invent a wheel.
, , -1 , Python . , while letters >= 0 while letters > 0.
, ( ):
- Python
for. , while . , . . +=, . , count = count + 1.- , , , .
char='e' , . - .
has_no_e() , , e, , , e.
, :
def count_letter(word, char='e'):
count = 0
for c in word:
if c == char:
count += 1
return count
:
>>> count_letter('tee')
2
>>> count_letter('tee', 't')
1
>>> count_letter('tee', 'f')
0
>>> count_letter('wh' + 'e'*100)
100