1ALLOWED_BUSH_TYPES = {'храст', 'shrub', 'bush'}
2
3def is_valid_bush_name(bush):
4 bush_name_lower = bush.get('name', '').lower()
5 if bush_name_lower in ALLOWED_BUSH_TYPES:
6 return True
7 return False
8
9def function_that_says_ni(*args, **kwargs):
10 sum_of_costs = 0
11 unique_letters = set()
12 for arg in args:
13 if type(arg) is dict and is_valid_bush_name(arg):
14 sum_of_costs += arg.get('cost', 0)
15 for key in kwargs:
16 if type(kwargs[key]) is dict and is_valid_bush_name(kwargs[key]):
17 sum_of_costs += kwargs[key].get('cost', 0)
18 unique_letters.update(key)
19
20 whole_part_of_costs = int(sum_of_costs)
21 if whole_part_of_costs <= 0:
22 return 'Ni!'
23
24 looks_nice = len(unique_letters) % whole_part_of_costs
25 if sum_of_costs > 42.00 or looks_nice != 0:
26 return 'Ni!'
27
28 return f'{sum_of_costs:.2f}лв'
..........
----------------------------------------------------------------------
Ran 10 tests in 0.000s
OK
| n | 1 | allowed_bush_types = {'храст', 'shrub', 'bush'} | n | 1 | ALLOWED_BUSH_TYPES = {'храст', 'shrub', 'bush'} |
| 2 | 2 | ||||
| 3 | def is_valid_bush_name(bush): | 3 | def is_valid_bush_name(bush): | ||
| n | 4 | if 'name' in bush: | n | ||
| 5 | bush_name_lower = bush['name'].lower() | 4 | bush_name_lower = bush.get('name', '').lower() | ||
| 6 | for bush_type in allowed_bush_types: | 5 | if bush_name_lower in ALLOWED_BUSH_TYPES: | ||
| 7 | if bush_type.lower() == bush_name_lower: | ||||
| 8 | return True | 6 | return True | ||
| 9 | return False | 7 | return False | ||
| 10 | 8 | ||||
| 11 | def function_that_says_ni(*args, **kwargs): | 9 | def function_that_says_ni(*args, **kwargs): | ||
| 12 | sum_of_costs = 0 | 10 | sum_of_costs = 0 | ||
| 13 | unique_letters = set() | 11 | unique_letters = set() | ||
| 14 | for arg in args: | 12 | for arg in args: | ||
| 15 | if type(arg) is dict and is_valid_bush_name(arg): | 13 | if type(arg) is dict and is_valid_bush_name(arg): | ||
| n | 16 | if 'cost' in arg: | n | 14 | sum_of_costs += arg.get('cost', 0) |
| 17 | sum_of_costs += arg['cost'] | ||||
| 18 | for key in kwargs: | 15 | for key in kwargs: | ||
| 19 | if type(kwargs[key]) is dict and is_valid_bush_name(kwargs[key]): | 16 | if type(kwargs[key]) is dict and is_valid_bush_name(kwargs[key]): | ||
| n | 20 | if 'cost' in kwargs[key]: | n | ||
| 21 | sum_of_costs += kwargs[key]['cost'] | 17 | sum_of_costs += kwargs[key].get('cost', 0) | ||
| 22 | unique_letters.update(key) | 18 | unique_letters.update(key) | ||
| 23 | 19 | ||||
| 24 | whole_part_of_costs = int(sum_of_costs) | 20 | whole_part_of_costs = int(sum_of_costs) | ||
| 25 | if whole_part_of_costs <= 0: | 21 | if whole_part_of_costs <= 0: | ||
| 26 | return 'Ni!' | 22 | return 'Ni!' | ||
| 27 | 23 | ||||
| 28 | looks_nice = len(unique_letters) % whole_part_of_costs | 24 | looks_nice = len(unique_letters) % whole_part_of_costs | ||
| 29 | if sum_of_costs > 42.00 or looks_nice != 0: | 25 | if sum_of_costs > 42.00 or looks_nice != 0: | ||
| 30 | return 'Ni!' | 26 | return 'Ni!' | ||
| 31 | 27 | ||||
| t | 32 | return (f'{sum_of_costs:.2f}лв') | t | 28 | return f'{sum_of_costs:.2f}лв' |
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||
| f | 1 | allowed_bush_types = {'храст', 'shrub', 'bush'} | f | 1 | allowed_bush_types = {'храст', 'shrub', 'bush'} |
| 2 | 2 | ||||
| 3 | def is_valid_bush_name(bush): | 3 | def is_valid_bush_name(bush): | ||
| 4 | if 'name' in bush: | 4 | if 'name' in bush: | ||
| 5 | bush_name_lower = bush['name'].lower() | 5 | bush_name_lower = bush['name'].lower() | ||
| 6 | for bush_type in allowed_bush_types: | 6 | for bush_type in allowed_bush_types: | ||
| 7 | if bush_type.lower() == bush_name_lower: | 7 | if bush_type.lower() == bush_name_lower: | ||
| 8 | return True | 8 | return True | ||
| 9 | return False | 9 | return False | ||
| 10 | 10 | ||||
| 11 | def function_that_says_ni(*args, **kwargs): | 11 | def function_that_says_ni(*args, **kwargs): | ||
| 12 | sum_of_costs = 0 | 12 | sum_of_costs = 0 | ||
| 13 | unique_letters = set() | 13 | unique_letters = set() | ||
| n | 14 | n | |||
| 15 | for arg in args: | 14 | for arg in args: | ||
| 16 | if type(arg) is dict and is_valid_bush_name(arg): | 15 | if type(arg) is dict and is_valid_bush_name(arg): | ||
| 17 | if 'cost' in arg: | 16 | if 'cost' in arg: | ||
| n | 18 | sum_of_costs += arg['cost'] | n | 17 | sum_of_costs += arg['cost'] |
| 19 | |||||
| 20 | for key in kwargs: | 18 | for key in kwargs: | ||
| 21 | if type(kwargs[key]) is dict and is_valid_bush_name(kwargs[key]): | 19 | if type(kwargs[key]) is dict and is_valid_bush_name(kwargs[key]): | ||
| 22 | if 'cost' in kwargs[key]: | 20 | if 'cost' in kwargs[key]: | ||
| 23 | sum_of_costs += kwargs[key]['cost'] | 21 | sum_of_costs += kwargs[key]['cost'] | ||
| 24 | unique_letters.update(key) | 22 | unique_letters.update(key) | ||
| 25 | 23 | ||||
| 26 | whole_part_of_costs = int(sum_of_costs) | 24 | whole_part_of_costs = int(sum_of_costs) | ||
| 27 | if whole_part_of_costs <= 0: | 25 | if whole_part_of_costs <= 0: | ||
| 28 | return 'Ni!' | 26 | return 'Ni!' | ||
| t | 29 | t | 27 | ||
| 30 | looks_nice = len(unique_letters) % whole_part_of_costs | 28 | looks_nice = len(unique_letters) % whole_part_of_costs | ||
| 31 | if sum_of_costs > 42.00 or looks_nice != 0: | 29 | if sum_of_costs > 42.00 or looks_nice != 0: | ||
| 32 | return 'Ni!' | 30 | return 'Ni!' | ||
| 33 | 31 | ||||
| 34 | return (f'{sum_of_costs:.2f}лв') | 32 | return (f'{sum_of_costs:.2f}лв') |
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||