1def function_that_says_ni(*args, **kwargs):
2 valid_shrubs = []
3 shrubbery_price = 0.0
4 shrubbery_types = ('храст', 'shrub', 'bush')
5 unique_symbols = set()
6 highest_price = 42.00
7
8 for arg in args:
9 if type(arg) is dict:
10 if 'name' in arg:
11 if arg['name'].lower() in shrubbery_types:
12 valid_shrubs.append(arg)
13
14 for key, value in kwargs.items():
15 if type(value) is dict:
16 if 'name' in value:
17 if value['name'].lower() in shrubbery_types:
18 valid_shrubs.append(value)
19 unique_symbols.update(key)
20
21 for shrub in valid_shrubs:
22 if 'cost' in shrub:
23 shrubbery_price += shrub['cost']
24
25 if int(shrubbery_price) == 0:
26 return 'Ni!'
27
28 good_price = shrubbery_price <= highest_price
29 good_looking = (len(unique_symbols) % int(shrubbery_price) == 0)
30
31 if good_price and good_looking:
32 price_str = f'{shrubbery_price:.2f}лв'
33 return price_str
34
35 return 'Ni!'
..........
----------------------------------------------------------------------
Ran 10 tests in 0.000s
OK
f | 1 | def function_that_says_ni(*args, **kwargs): | f | 1 | def function_that_says_ni(*args, **kwargs): |
2 | valid_shrubs = [] | 2 | valid_shrubs = [] | ||
3 | shrubbery_price = 0.0 | 3 | shrubbery_price = 0.0 | ||
4 | shrubbery_types = ('храст', 'shrub', 'bush') | 4 | shrubbery_types = ('храст', 'shrub', 'bush') | ||
5 | unique_symbols = set() | 5 | unique_symbols = set() | ||
6 | highest_price = 42.00 | 6 | highest_price = 42.00 | ||
7 | 7 | ||||
8 | for arg in args: | 8 | for arg in args: | ||
9 | if type(arg) is dict: | 9 | if type(arg) is dict: | ||
10 | if 'name' in arg: | 10 | if 'name' in arg: | ||
11 | if arg['name'].lower() in shrubbery_types: | 11 | if arg['name'].lower() in shrubbery_types: | ||
12 | valid_shrubs.append(arg) | 12 | valid_shrubs.append(arg) | ||
13 | 13 | ||||
14 | for key, value in kwargs.items(): | 14 | for key, value in kwargs.items(): | ||
15 | if type(value) is dict: | 15 | if type(value) is dict: | ||
16 | if 'name' in value: | 16 | if 'name' in value: | ||
t | 17 | if value['name'].lower() == 'храст' or value['name'].lower() == 'shrub' or value['name'].lower() == 'bush': | t | 17 | if value['name'].lower() in shrubbery_types: |
18 | valid_shrubs.append(value) | 18 | valid_shrubs.append(value) | ||
19 | unique_symbols.update(key) | 19 | unique_symbols.update(key) | ||
20 | 20 | ||||
21 | for shrub in valid_shrubs: | 21 | for shrub in valid_shrubs: | ||
22 | if 'cost' in shrub: | 22 | if 'cost' in shrub: | ||
23 | shrubbery_price += shrub['cost'] | 23 | shrubbery_price += shrub['cost'] | ||
24 | 24 | ||||
25 | if int(shrubbery_price) == 0: | 25 | if int(shrubbery_price) == 0: | ||
26 | return 'Ni!' | 26 | return 'Ni!' | ||
27 | 27 | ||||
28 | good_price = shrubbery_price <= highest_price | 28 | good_price = shrubbery_price <= highest_price | ||
29 | good_looking = (len(unique_symbols) % int(shrubbery_price) == 0) | 29 | good_looking = (len(unique_symbols) % int(shrubbery_price) == 0) | ||
30 | 30 | ||||
31 | if good_price and good_looking: | 31 | if good_price and good_looking: | ||
32 | price_str = f'{shrubbery_price:.2f}лв' | 32 | price_str = f'{shrubbery_price:.2f}лв' | ||
33 | return price_str | 33 | return price_str | ||
34 | 34 | ||||
35 | return 'Ni!' | 35 | return 'Ni!' |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | def function_that_says_ni(*args, **kwargs): | f | 1 | def function_that_says_ni(*args, **kwargs): |
2 | valid_shrubs = [] | 2 | valid_shrubs = [] | ||
3 | shrubbery_price = 0.0 | 3 | shrubbery_price = 0.0 | ||
n | n | 4 | shrubbery_types = ('храст', 'shrub', 'bush') | ||
4 | unique_symbols = set() | 5 | unique_symbols = set() | ||
5 | highest_price = 42.00 | 6 | highest_price = 42.00 | ||
n | 6 | good_price = False | n | ||
7 | good_looking = False | ||||
8 | 7 | ||||
9 | for arg in args: | 8 | for arg in args: | ||
10 | if type(arg) is dict: | 9 | if type(arg) is dict: | ||
n | 11 | if 'name' in arg.keys(): | n | 10 | if 'name' in arg: |
12 | if arg['name'].lower() == 'храст' or arg['name'].lower() == 'shrub' or arg['name'].lower() == 'bush': | 11 | if arg['name'].lower() in shrubbery_types: | ||
13 | valid_shrubs.append(arg) | 12 | valid_shrubs.append(arg) | ||
14 | 13 | ||||
15 | for key, value in kwargs.items(): | 14 | for key, value in kwargs.items(): | ||
16 | if type(value) is dict: | 15 | if type(value) is dict: | ||
n | 17 | if 'name' in value.keys(): | n | 16 | if 'name' in value: |
18 | if value['name'].lower() == 'храст' or value['name'].lower() == 'shrub' or value['name'].lower() == 'bush': | 17 | if value['name'].lower() == 'храст' or value['name'].lower() == 'shrub' or value['name'].lower() == 'bush': | ||
19 | valid_shrubs.append(value) | 18 | valid_shrubs.append(value) | ||
n | 20 | for curr_symbol in range(len(key)): | n | ||
21 | unique_symbols.add(key[curr_symbol]) | 19 | unique_symbols.update(key) | ||
22 | 20 | ||||
23 | for shrub in valid_shrubs: | 21 | for shrub in valid_shrubs: | ||
n | 24 | if 'cost' in shrub.keys(): | n | 22 | if 'cost' in shrub: |
25 | shrubbery_price += shrub['cost'] | 23 | shrubbery_price += shrub['cost'] | ||
26 | 24 | ||||
27 | if int(shrubbery_price) == 0: | 25 | if int(shrubbery_price) == 0: | ||
28 | return 'Ni!' | 26 | return 'Ni!' | ||
29 | 27 | ||||
n | 30 | if shrubbery_price <= highest_price: | n | 28 | good_price = shrubbery_price <= highest_price |
31 | good_price = True | ||||
32 | |||||
33 | if len(unique_symbols) % int(shrubbery_price) == 0: | 29 | good_looking = (len(unique_symbols) % int(shrubbery_price) == 0) | ||
34 | good_looking = True | ||||
35 | 30 | ||||
36 | if good_price and good_looking: | 31 | if good_price and good_looking: | ||
37 | price_str = f'{shrubbery_price:.2f}лв' | 32 | price_str = f'{shrubbery_price:.2f}лв' | ||
38 | return price_str | 33 | return price_str | ||
39 | 34 | ||||
40 | return 'Ni!' | 35 | return 'Ni!' | ||
t | 41 | t |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|