1list_shrub = ["храст", "shrub", "bush"]
2
3def sum_positional_bush_price(*args):
4 result = 0.00
5 for item in args:
6 if type(item) == dict and 'name' in item:
7 if item['name'].lower() in list_shrub:
8 result += item.get('cost', 0)
9
10 return result
11
12
13def sum_naming_bush_price(unique_set, **kwargs):
14 result = 0.00
15 for name, bush in kwargs.items():
16 if type(bush) == dict and 'name' in bush:
17 if bush['name'].lower() in list_shrub:
18 for letter in name:
19 unique_set.add(letter)
20 if 'cost' in bush:
21 result += bush['cost']
22 return result
23
24
25def function_that_says_ni(*args, **kwargs):
26 price = 0.00
27 price += sum_positional_bush_price(*args)
28
29 unique_set = set()
30 price += sum_naming_bush_price(unique_set, **kwargs)
31
32 price_in_int = int(price)
33 if 0 < price_in_int <= 42:
34 if len(unique_set) % price_in_int == 0:
35 return f"{price:.2f}лв"
36
37 return "Ni!"
.....F....
======================================================================
FAIL: test_multiple_shrubs_sumс (test.TestNi.test_multiple_shrubs_sumс)
Test with a multiple shrubs and cornercase costs.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 38, in test_multiple_shrubs_sumс
self.assertEqual(function_that_says_ni({'name': 'shrub', 'cost': 20.01},
AssertionError: '42.01лв' != 'Ni!'
- 42.01лв
+ Ni!
----------------------------------------------------------------------
Ran 10 tests in 0.001s
FAILED (failures=1)
| f | 1 | f | 1 | ||
| 2 | list_shrub = ["храст", "shrub", "bush"] | 2 | list_shrub = ["храст", "shrub", "bush"] | ||
| 3 | 3 | ||||
| 4 | def sum_positional_bush_price(*args): | 4 | def sum_positional_bush_price(*args): | ||
| n | 5 | result = 0 | n | 5 | result = 0.00 |
| 6 | for item in args: | 6 | for item in args: | ||
| 7 | if type(item) == dict and 'name' in item: | 7 | if type(item) == dict and 'name' in item: | ||
| 8 | if item['name'].lower() in list_shrub: | 8 | if item['name'].lower() in list_shrub: | ||
| 9 | result += item.get('cost', 0) | 9 | result += item.get('cost', 0) | ||
| 10 | 10 | ||||
| 11 | return result | 11 | return result | ||
| 12 | 12 | ||||
| 13 | 13 | ||||
| 14 | def sum_naming_bush_price(unique_set, **kwargs): | 14 | def sum_naming_bush_price(unique_set, **kwargs): | ||
| t | 15 | result = 0 | t | 15 | result = 0.00 |
| 16 | for name, bush in kwargs.items(): | 16 | for name, bush in kwargs.items(): | ||
| 17 | if type(bush) == dict and 'name' in bush: | 17 | if type(bush) == dict and 'name' in bush: | ||
| 18 | if bush['name'].lower() in list_shrub: | 18 | if bush['name'].lower() in list_shrub: | ||
| 19 | for letter in name: | 19 | for letter in name: | ||
| 20 | unique_set.add(letter) | 20 | unique_set.add(letter) | ||
| 21 | if 'cost' in bush: | 21 | if 'cost' in bush: | ||
| 22 | result += bush['cost'] | 22 | result += bush['cost'] | ||
| 23 | return result | 23 | return result | ||
| 24 | 24 | ||||
| 25 | 25 | ||||
| 26 | def function_that_says_ni(*args, **kwargs): | 26 | def function_that_says_ni(*args, **kwargs): | ||
| 27 | price = 0.00 | 27 | price = 0.00 | ||
| 28 | price += sum_positional_bush_price(*args) | 28 | price += sum_positional_bush_price(*args) | ||
| 29 | 29 | ||||
| 30 | unique_set = set() | 30 | unique_set = set() | ||
| 31 | price += sum_naming_bush_price(unique_set, **kwargs) | 31 | price += sum_naming_bush_price(unique_set, **kwargs) | ||
| 32 | 32 | ||||
| 33 | price_in_int = int(price) | 33 | price_in_int = int(price) | ||
| 34 | if 0 < price_in_int <= 42: | 34 | if 0 < price_in_int <= 42: | ||
| 35 | if len(unique_set) % price_in_int == 0: | 35 | if len(unique_set) % price_in_int == 0: | ||
| 36 | return f"{price:.2f}лв" | 36 | return f"{price:.2f}лв" | ||
| 37 | 37 | ||||
| 38 | return "Ni!" | 38 | return "Ni!" |
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||
| f | 1 | f | 1 | ||
| 2 | list_shrub = ["храст", "shrub", "bush"] | 2 | list_shrub = ["храст", "shrub", "bush"] | ||
| 3 | 3 | ||||
| n | 4 | def positional_parameter(price, *args): | n | 4 | def sum_positional_bush_price(*args): |
| 5 | result = 0 | ||||
| 5 | for item in args: | 6 | for item in args: | ||
| n | 6 | if type(item) == dict and 'name' in item.keys(): | n | 7 | if type(item) == dict and 'name' in item: |
| 7 | if item['name'].lower() in list_shrub: | 8 | if item['name'].lower() in list_shrub: | ||
| n | 8 | if 'cost' in item.keys(): | n | 9 | result += item.get('cost', 0) |
| 9 | price += item['cost'] | ||||
| 10 | 10 | ||||
| n | 11 | return price | n | 11 | return result |
| 12 | 12 | ||||
| n | n | 13 | |||
| 13 | def naming_parameter(price, unique_set, **kwargs): | 14 | def sum_naming_bush_price(unique_set, **kwargs): | ||
| 15 | result = 0 | ||||
| 14 | for name, bush in kwargs.items(): | 16 | for name, bush in kwargs.items(): | ||
| n | 15 | if type(bush) == dict and 'name' in bush.keys(): | n | 17 | if type(bush) == dict and 'name' in bush: |
| 16 | if bush['name'].lower() in list_shrub: | 18 | if bush['name'].lower() in list_shrub: | ||
| 17 | for letter in name: | 19 | for letter in name: | ||
| 18 | unique_set.add(letter) | 20 | unique_set.add(letter) | ||
| n | 19 | if 'cost' in bush.keys(): | n | 21 | if 'cost' in bush: |
| 20 | price += bush['cost'] | 22 | result += bush['cost'] | ||
| 21 | return price | 23 | return result | ||
| 22 | 24 | ||||
| 23 | 25 | ||||
| 24 | def function_that_says_ni(*args, **kwargs): | 26 | def function_that_says_ni(*args, **kwargs): | ||
| 25 | price = 0.00 | 27 | price = 0.00 | ||
| n | 26 | price = positional_parameter(price, *args) | n | 28 | price += sum_positional_bush_price(*args) |
| 27 | 29 | ||||
| 28 | unique_set = set() | 30 | unique_set = set() | ||
| n | 29 | price = naming_parameter(price, unique_set, **kwargs) | n | 31 | price += sum_naming_bush_price(unique_set, **kwargs) |
| 30 | 32 | ||||
| 31 | price_in_int = int(price) | 33 | price_in_int = int(price) | ||
| 32 | if 0 < price_in_int <= 42: | 34 | if 0 < price_in_int <= 42: | ||
| 33 | if len(unique_set) % price_in_int == 0: | 35 | if len(unique_set) % price_in_int == 0: | ||
| 34 | return f"{price:.2f}лв" | 36 | return f"{price:.2f}лв" | ||
| 35 | 37 | ||||
| 36 | return "Ni!" | 38 | return "Ni!" | ||
| t | 37 | t | |||
| 38 | |||||
| 39 | |||||
| 40 | |||||
| 41 |
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||