Skip to content

Commit

Permalink
'Solution'
Browse files Browse the repository at this point in the history
  • Loading branch information
Viva1337 committed Nov 16, 2024
1 parent 5367f8f commit ee3372a
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
def count_occurrences(phrase: str, letter: str) -> int:
# write your code here
pass
"""
Подсчитывает количество вхождений буквы в строку (регистронезависимо).
:param phrase: Строка, в которой нужно искать букву.
:param letter: Буква, чьи вхождения нужно подсчитать.
:return: Количество вхождений буквы в строке.
"""
# Проверка корректности входных данных
if not isinstance(phrase, str) or not isinstance(letter, str):
raise ValueError(
"Оба параметра, phrase и letter, должны быть строками."
)
if len(letter) != 1:
raise ValueError("Параметр letter должен быть одним символом.")

# Приведение строки и буквы к нижнему регистру и подсчет
return phrase.lower().count(letter.lower())


# Примеры использования
print(count_occurrences("letter", "t")) # 2
print(count_occurrences("abc", "a")) # 1
print(count_occurrences("abc", "d")) # 0
print(count_occurrences("ABC", "a")) # 1

0 comments on commit ee3372a

Please sign in to comment.