Skip to content

Commit 8ebe734

Browse files
Merge pull request #1910 from vsmutok/update-readme
2 parents 7e7a3ee + 8feb6dd commit 8ebe734

File tree

2 files changed

+37
-16
lines changed

2 files changed

+37
-16
lines changed

README.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,39 @@
11
# Count Occurrences
22

33
- Read [the guideline](https://github.com/mate-academy/py-task-guideline/blob/main/README.md) before start
4-
- Implement the task described [here](app/main.py)
4+
5+
## Task Description
6+
7+
You are required to implement the `count_occurrences` function that takes two parameters:
8+
9+
1. **phrase**: A string in which to count occurrences of a letter.
10+
2. **letter**: The letter whose occurrences need to be counted in the given phrase.
11+
12+
The function should return the number of times the letter appears in the phrase, while being **case insensitive**.
13+
14+
### Examples:
15+
16+
- `count_occurrences("letter", "t")` should return `2`
17+
- `count_occurrences("abc", "a")` should return `1`
18+
- `count_occurrences("abc", "d")` should return `0`
19+
- `count_occurrences("ABC", "a")` should return `1`
20+
21+
### Function Signature:
22+
23+
```python
24+
def count_occurrences(phrase: str, letter: str) -> int:
25+
"""
26+
Count occurrences of a letter in a phrase (case insensitive).
27+
28+
:param phrase: The phrase to search within.
29+
:param letter: The letter to count occurrences of.
30+
:return: The number of occurrences of the letter in the phrase.
31+
"""
32+
```
33+
34+
## Guidelines
35+
36+
- The function must be **case insensitive**. This means that both the phrase and the letter should be treated as if they are in the same case (upper or lower).
37+
38+
- It is **recommended** to avoid using loops to solve this task. Instead, consider utilizing Python's built-in string functions to simplify the solution.
39+

app/main.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
11
def count_occurrences(phrase: str, letter: str) -> int:
2-
"""
3-
Implement count_occurrences function:
4-
5-
It takes a phrase and a letter and calculates the number of times
6-
the letter appears in the phrase. The function is case insensitive.
7-
8-
count_occurrences("letter", "t") == 2
9-
count_occurrences("abc", "a") == 1
10-
count_occurrences("abc", "d") == 0
11-
count_occurrences("ABC", "a") == 1
12-
13-
:param phrase: phrase to count in it
14-
:param letter: letter to find occurrences of it
15-
:return: count occurrences of letter in phrase
16-
"""
172
# write your code here
3+
pass

0 commit comments

Comments
 (0)