How Many of That Letter?

Python FundamentalsMedium+10 XP+10

How Many of That Letter?

Write a function count_letter(word, letter) that returns how many times letter appears in word.

  • letter is always a single character.
  • Capitals count as different letters: "A" is not the same as "a".
  • If word is empty (""), return 0.

Examples

word = "banana"
letter = "a"
returns 3
word = "coffee"
letter = "z"
returns 0
word = "coffee"
letter = "f"
returns 2

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run