File tree Expand file tree Collapse file tree 3 files changed +37
-8
lines changed Expand file tree Collapse file tree 3 files changed +37
-8
lines changed Original file line number Diff line number Diff line change 1- # Python boilerplate for GitHub tasks
1+ # Count Occurrences
22
33- Read [ the guideline] ( https://github.com/mate-academy/py-task-guideline/blob/main/README.md ) before start
44- Implement the task described [ here] ( app/main.py )
Original file line number Diff line number Diff line change 1- # TODO: add initial code
2- def hello_world ():
3- return "Hello, world!"
1+ 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+ """
17+ # write your code here
Original file line number Diff line number Diff line change 1- # TODO: add tests
2- from app .main import hello_world
1+ import pytest
32
3+ from app .main import count_occurrences
44
5- def test_hello_world ():
6- assert hello_world () == "Hello, world!"
5+
6+ @pytest .mark .parametrize (
7+ "phrase,letter,count" ,
8+ [
9+ ("samsung" , "a" , 1 ),
10+ ("samsung is gnusmas" , "s" , 5 ),
11+ ("Samsung is gnusmas" , "s" , 5 ),
12+ ("Abracadabra" , "A" , 5 ),
13+ ("" , "a" , 0 ),
14+ ("Samsung" , "b" , 0 ),
15+ ]
16+ )
17+ def test_count_occurrences (phrase , letter , count ):
18+ assert count_occurrences (phrase , letter ) == count , (
19+ f"Function 'count_occurrences' should return { count } , "
20+ f"when 'phrase'='{ phrase } ' and 'letter'='{ letter } '"
21+ )
You can’t perform that action at this time.
0 commit comments