CodeTestValidate

No installations needed! Write Python directly in your browser and get instant feedback with our smart validation system.

Challenge # 6

Count Character Occurrences

Objective

Count the number of times a specific character appears in a string.

Instructions

  • You are given a string text and a character target_char.

  • Count how many times target_char appears in text.

  • Print the count.

Constraints:
Do not use input(). • `text` is a string and `target_char` is a single-character string.
Exemple IO

Input: text = "hello world" target_char = "l"

Output: 3

Input: text = "banana" target_char = "a"

Output: 3

Input: text = "python" target_char = "z"

Output: 0

Try It Online!

Output:

Validate Your Results

Get your code reviewed and validated to understand what you did right and where you can improve.

Previous challengeRemove Duplicates from a ListNext challengeMerge Two Dictionaries
Loading...