Count Specific Letter

Beginner

Let's have fun counting letters! Your challenge is to create a function that counts how many times a specific letter appears in a given string. This is a great way to practice looping through strings and using conditionals in Python.

Task

Write a function count_specific_letter that takes two arguments:

  • A string text
  • A character letter

Your function should return the number of times letter appears in text.

Examples

Let's look at some examples of what your function should do:

count_specific_letter("hello world", "o")

This should return 2 because the letter "o" appears twice in the string "hello world".

count_specific_letter("apple pie", "p")

This should return 2 because the letter "p" appears twice in "apple pie".

count_specific_letter("banana", "a")

This should return 3 because "a" appears three times in "banana".

Note

  • The function should be case-sensitive, so "A" and "a" are considered different characters.
Geek
Inputs

Arg 1:

"hello world"

Arg 2:

"o"
Expected Output
2
Actual Output
Count Specific Letter [beginner] | Coding for Kids