1def get_count_unique_letters_for_keys(**kwargs):
2
3 unique_letters = set()
4 for key, value in kwargs.items():
5 unique_letters.update(key)
6
7 return len(unique_letters)
8
9valid_bush_names = ['храст', 'bush', 'shrub']
10
11def function_that_says_ni(*args, **kwargs):
12 cost = 0
13 has_named = False
14
15 # execute for kwargs(named)
16 count = get_count_unique_letters_for_keys(**kwargs)
17
18 for name, dictionary in kwargs.items():
19 if 'name' in dictionary and dictionary.get('name').lower() in valid_bush_names: #Good bush
20 cost += dictionary.get('cost', 0)
21 has_named = True
22
23 # execute for args(positional)
24 for arg in args:
25 if type(arg) is not dict:
26 continue
27
28 dictionary = dict(arg)
29
30 if 'name' in dictionary and dictionary['name'].lower() in valid_bush_names:
31 cost += dictionary.get('cost', 0)
32
33 if cost == 0 or cost > 42:
34 return 'Ni!'
35 if has_named and count % (cost // 1) != 0:
36 return 'Ni!'
37
38 return f'{cost:.2f}лв'
..F.......
======================================================================
FAIL: test_cost_whole_part_zero (test.TestNi.test_cost_whole_part_zero)
Test with a total cost part equal to zero.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 43, in test_cost_whole_part_zero
self.assertEqual(function_that_says_ni({'name': 'shrub', 'cost': 0.1},
AssertionError: '0.30лв' != 'Ni!'
- 0.30лв
+ Ni!
----------------------------------------------------------------------
Ran 10 tests in 0.001s
FAILED (failures=1)
t | 1 | def get_count_unique_letters_for_keys(**kwargs): | t | 1 | def get_count_unique_letters_for_keys(**kwargs): |
2 | 2 | ||||
3 | unique_letters = set() | 3 | unique_letters = set() | ||
4 | for key, value in kwargs.items(): | 4 | for key, value in kwargs.items(): | ||
5 | unique_letters.update(key) | 5 | unique_letters.update(key) | ||
6 | 6 | ||||
7 | return len(unique_letters) | 7 | return len(unique_letters) | ||
8 | 8 | ||||
9 | valid_bush_names = ['храст', 'bush', 'shrub'] | 9 | valid_bush_names = ['храст', 'bush', 'shrub'] | ||
10 | 10 | ||||
11 | def function_that_says_ni(*args, **kwargs): | 11 | def function_that_says_ni(*args, **kwargs): | ||
12 | cost = 0 | 12 | cost = 0 | ||
13 | has_named = False | 13 | has_named = False | ||
14 | 14 | ||||
15 | # execute for kwargs(named) | 15 | # execute for kwargs(named) | ||
16 | count = get_count_unique_letters_for_keys(**kwargs) | 16 | count = get_count_unique_letters_for_keys(**kwargs) | ||
17 | 17 | ||||
18 | for name, dictionary in kwargs.items(): | 18 | for name, dictionary in kwargs.items(): | ||
19 | if 'name' in dictionary and dictionary.get('name').lower() in valid_bush_names: #Good bush | 19 | if 'name' in dictionary and dictionary.get('name').lower() in valid_bush_names: #Good bush | ||
20 | cost += dictionary.get('cost', 0) | 20 | cost += dictionary.get('cost', 0) | ||
21 | has_named = True | 21 | has_named = True | ||
22 | 22 | ||||
23 | # execute for args(positional) | 23 | # execute for args(positional) | ||
24 | for arg in args: | 24 | for arg in args: | ||
25 | if type(arg) is not dict: | 25 | if type(arg) is not dict: | ||
26 | continue | 26 | continue | ||
27 | 27 | ||||
28 | dictionary = dict(arg) | 28 | dictionary = dict(arg) | ||
29 | 29 | ||||
30 | if 'name' in dictionary and dictionary['name'].lower() in valid_bush_names: | 30 | if 'name' in dictionary and dictionary['name'].lower() in valid_bush_names: | ||
31 | cost += dictionary.get('cost', 0) | 31 | cost += dictionary.get('cost', 0) | ||
32 | 32 | ||||
33 | if cost == 0 or cost > 42: | 33 | if cost == 0 or cost > 42: | ||
34 | return 'Ni!' | 34 | return 'Ni!' | ||
35 | if has_named and count % (cost // 1) != 0: | 35 | if has_named and count % (cost // 1) != 0: | ||
36 | return 'Ni!' | 36 | return 'Ni!' | ||
37 | 37 | ||||
38 | return f'{cost:.2f}лв' | 38 | return f'{cost:.2f}лв' | ||
39 | 39 |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | def get_count_unique_letters_for_keys(**kwargs): | f | 1 | def get_count_unique_letters_for_keys(**kwargs): |
2 | 2 | ||||
3 | unique_letters = set() | 3 | unique_letters = set() | ||
4 | for key, value in kwargs.items(): | 4 | for key, value in kwargs.items(): | ||
5 | unique_letters.update(key) | 5 | unique_letters.update(key) | ||
6 | 6 | ||||
7 | return len(unique_letters) | 7 | return len(unique_letters) | ||
8 | 8 | ||||
9 | valid_bush_names = ['храст', 'bush', 'shrub'] | 9 | valid_bush_names = ['храст', 'bush', 'shrub'] | ||
10 | 10 | ||||
11 | def function_that_says_ni(*args, **kwargs): | 11 | def function_that_says_ni(*args, **kwargs): | ||
12 | cost = 0 | 12 | cost = 0 | ||
n | n | 13 | has_named = False | ||
13 | 14 | ||||
n | 14 | if len(args) == 0: | n | 15 | # execute for kwargs(named) |
15 | #execute for named arguments | ||||
16 | count = get_count_unique_letters_for_keys(**kwargs) | 16 | count = get_count_unique_letters_for_keys(**kwargs) | ||
17 | 17 | ||||
n | 18 | for name, dictionary in kwargs.items(): | n | 18 | for name, dictionary in kwargs.items(): |
19 | if 'name' in dictionary and dictionary['name'].lower() in valid_bush_names: #Good bush | 19 | if 'name' in dictionary and dictionary.get('name').lower() in valid_bush_names: #Good bush | ||
20 | if 'cost' in dictionary: | ||||
21 | cost += dictionary['cost'] | 20 | cost += dictionary.get('cost', 0) | ||
21 | has_named = True | ||||
22 | 22 | ||||
n | 23 | if count % (cost // 1) != 0: | n | 23 | # execute for args(positional) |
24 | return 'Ni' | 24 | for arg in args: | ||
25 | if type(arg) is not dict: | ||||
26 | continue | ||||
25 | 27 | ||||
n | 26 | else: | n | 28 | dictionary = dict(arg) |
27 | #execute for one dictionary | ||||
28 | 29 | ||||
n | 29 | for arg in args: | n | 30 | if 'name' in dictionary and dictionary['name'].lower() in valid_bush_names: |
30 | dictionary = dict(arg) | 31 | cost += dictionary.get('cost', 0) | ||
31 | 32 | ||||
n | 32 | if 'name' in dictionary and dictionary['name'].lower() in valid_bush_names: | n | 33 | if cost == 0 or cost > 42: |
33 | if 'cost' in dictionary: | ||||
34 | if dictionary['cost'] // 1 > 42: | ||||
35 | return 'Ni' | ||||
36 | else: | ||||
37 | cost += dictionary['cost'] | ||||
38 | else: | ||||
39 | return 'Ni' | 34 | return 'Ni!' | ||
35 | if has_named and count % (cost // 1) != 0: | ||||
36 | return 'Ni!' | ||||
40 | 37 | ||||
41 | return f'{cost:.2f}лв' | 38 | return f'{cost:.2f}лв' | ||
42 | 39 | ||||
t | 43 | t |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|