Character Count
Given a string s and a character ch, count how many times that character appears in the string. This is useful when analyzing text, finding frequent letters, or checking user input. Return the number of matches.
Примеры
Ввод
"banana", "a"Вывод
3Ввод
"hello", "z"Вывод
0Ввод
"aaa", "a"Вывод
3Нужно реализовать
def count_char(s: str, ch: str) -> int:
Теги
strings
Prihláste sa, aby ste videli históriu odoslaní
Prihlásiť saPrihláste sa, aby ste mohli používať AI mentora
Prihlásiť saVisible tests
1
Input
"banana", "a"Expected
32
Input
"hello", "z"Expected
03
Input
"aaa", "a"Expected
34
Input
"banana", "A"Expected
05
Input
"banana", "Hello, World!"Expected
06
Input
"aaa", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"Expected
0Focus radio
Paused · SomaFM · Fluid