Count Occurrences of Character
Advanced
Welcome to the "Count Occurrences of Character" challenge! π
In this fun and educational challenge, you will create a function to help count how many times a specific character appears in a given sentence. Think of it like being a detective, but for letters! π
Let's say we have the sentence: "I love coding!", and our target character is 'o'.
Your task is to count the number of times 'o' appears in the sentence.
Example:
count_occurrences("I love coding!", 'o')
This would return 2 because the letter 'o' appears twice.
Try out with different sentences and characters, and see if your function can find all the occurrences each time! π―
Here are more examples:
count_occurrences("Bananas are great!", 'a')should return4.count_occurrences("Hello, World!", 'l')should return3.
Let's start making those characters feel counted! β¨
Inputs
Arg 1:
"I love coding!"Arg 2:
"o"Expected Output
2Actual Output