1def function_that_says_ni(*args, **kwargs):
2 total_price = 0
3 valid_bushes = False
4 for arg in args:
5 if isinstance(arg, dict) and is_bush(arg):
6 valid_bushes = True
7 total_price += cost_of_bush(arg)
8
9 for kwarg_value in kwargs.values():
10 if isinstance(kwarg_value, dict) and is_bush(kwarg_value):
11 valid_bushes = True
12 total_price += cost_of_bush(kwarg_value)
13
14 output = generate_output(kwargs, total_price, valid_bushes)
15 return output
16
17def generate_output(kwargs, total_price, valid_bushes):
18 output_text = 'Ni!'
19 if valid_bushes == False:
20 return output_text
21 elif not one_that_looks_nice(kwargs, total_price) or is_too_expensive(total_price):
22 return output_text
23 else:
24 return f'{total_price:.2f}лв'
25
26def is_bush(arg):
27 key = 'name'
28 return key in arg.keys() and str(arg[key]).lower() in ('храст', 'shrub', 'bush')
29
30def cost_of_bush(arg):
31 value = 'cost'
32 if value in arg.keys() and isinstance(arg[value], (int, float)):
33 price = arg[value]
34 return price
35 return 0
36
37def one_that_looks_nice(kwargs, price):
38 whole_part_price = int(price)
39 if whole_part_price == 0:
40 return False
41 if len(kwargs) == 0:
42 return True
43 elif kwargs:
44 unique_chars = set()
45 for kwarg_key, kwarg_value in kwargs.items():
46 if isinstance(kwarg_value, dict) and is_bush(kwarg_value):
47 unique_chars.update(kwarg_key)
48 unique_chars_count = len(unique_chars)
49 looks_nice = unique_chars_count % whole_part_price == 0
50 return looks_nice
51 else:
52 return False
53
54def is_too_expensive(price):
55 return price > 42.00
..........
----------------------------------------------------------------------
Ran 10 tests in 0.000s
OK
Росица Илиева
20.10.2024 12:53Мерси много за обратната връзка. Ще се поправя!🙂
|
f | 1 | def function_that_says_ni(*args, **kwargs): | f | 1 | def function_that_says_ni(*args, **kwargs): |
2 | total_price = 0 | 2 | total_price = 0 | ||
3 | valid_bushes = False | 3 | valid_bushes = False | ||
4 | for arg in args: | 4 | for arg in args: | ||
n | 5 | if isinstance(arg, dict): | n | 5 | if isinstance(arg, dict) and is_bush(arg): |
6 | if is_bush(arg): | ||||
7 | valid_bushes = True | 6 | valid_bushes = True | ||
8 | total_price += cost_of_bush(arg) | 7 | total_price += cost_of_bush(arg) | ||
9 | 8 | ||||
10 | for kwarg_value in kwargs.values(): | 9 | for kwarg_value in kwargs.values(): | ||
n | 11 | if isinstance(kwarg_value, dict): | n | 10 | if isinstance(kwarg_value, dict) and is_bush(kwarg_value): |
12 | if is_bush(kwarg_value): | ||||
13 | valid_bushes = True | 11 | valid_bushes = True | ||
14 | total_price += cost_of_bush(kwarg_value) | 12 | total_price += cost_of_bush(kwarg_value) | ||
15 | 13 | ||||
16 | output = generate_output(kwargs, total_price, valid_bushes) | 14 | output = generate_output(kwargs, total_price, valid_bushes) | ||
17 | return output | 15 | return output | ||
18 | 16 | ||||
19 | def generate_output(kwargs, total_price, valid_bushes): | 17 | def generate_output(kwargs, total_price, valid_bushes): | ||
20 | output_text = 'Ni!' | 18 | output_text = 'Ni!' | ||
21 | if valid_bushes == False: | 19 | if valid_bushes == False: | ||
22 | return output_text | 20 | return output_text | ||
23 | elif not one_that_looks_nice(kwargs, total_price) or is_too_expensive(total_price): | 21 | elif not one_that_looks_nice(kwargs, total_price) or is_too_expensive(total_price): | ||
24 | return output_text | 22 | return output_text | ||
25 | else: | 23 | else: | ||
26 | return f'{total_price:.2f}лв' | 24 | return f'{total_price:.2f}лв' | ||
27 | 25 | ||||
28 | def is_bush(arg): | 26 | def is_bush(arg): | ||
29 | key = 'name' | 27 | key = 'name' | ||
30 | return key in arg.keys() and str(arg[key]).lower() in ('храст', 'shrub', 'bush') | 28 | return key in arg.keys() and str(arg[key]).lower() in ('храст', 'shrub', 'bush') | ||
31 | 29 | ||||
32 | def cost_of_bush(arg): | 30 | def cost_of_bush(arg): | ||
33 | value = 'cost' | 31 | value = 'cost' | ||
34 | if value in arg.keys() and isinstance(arg[value], (int, float)): | 32 | if value in arg.keys() and isinstance(arg[value], (int, float)): | ||
35 | price = arg[value] | 33 | price = arg[value] | ||
36 | return price | 34 | return price | ||
37 | return 0 | 35 | return 0 | ||
38 | 36 | ||||
39 | def one_that_looks_nice(kwargs, price): | 37 | def one_that_looks_nice(kwargs, price): | ||
40 | whole_part_price = int(price) | 38 | whole_part_price = int(price) | ||
41 | if whole_part_price == 0: | 39 | if whole_part_price == 0: | ||
42 | return False | 40 | return False | ||
43 | if len(kwargs) == 0: | 41 | if len(kwargs) == 0: | ||
44 | return True | 42 | return True | ||
45 | elif kwargs: | 43 | elif kwargs: | ||
46 | unique_chars = set() | 44 | unique_chars = set() | ||
47 | for kwarg_key, kwarg_value in kwargs.items(): | 45 | for kwarg_key, kwarg_value in kwargs.items(): | ||
t | 48 | if isinstance(kwarg_value, dict) and kwarg_value['name'] in ('храст', 'shrub', 'bush'): | t | 46 | if isinstance(kwarg_value, dict) and is_bush(kwarg_value): |
49 | unique_chars.update(kwarg_key) | 47 | unique_chars.update(kwarg_key) | ||
50 | unique_chars_count = len(unique_chars) | 48 | unique_chars_count = len(unique_chars) | ||
51 | looks_nice = unique_chars_count % whole_part_price == 0 | 49 | looks_nice = unique_chars_count % whole_part_price == 0 | ||
52 | return looks_nice | 50 | return looks_nice | ||
53 | else: | 51 | else: | ||
54 | return False | 52 | return False | ||
55 | 53 | ||||
56 | def is_too_expensive(price): | 54 | def is_too_expensive(price): | ||
57 | return price > 42.00 | 55 | return price > 42.00 |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | def function_that_says_ni(*args, **kwargs): | f | 1 | def function_that_says_ni(*args, **kwargs): |
2 | total_price = 0 | 2 | total_price = 0 | ||
n | 3 | valid_bushes = 0 | n | 3 | valid_bushes = False |
4 | for arg in args: | 4 | for arg in args: | ||
5 | if isinstance(arg, dict): | 5 | if isinstance(arg, dict): | ||
n | 6 | if is_a_bush_validation(arg): | n | 6 | if is_bush(arg): |
7 | valid_bushes += 1 | 7 | valid_bushes = True | ||
8 | total_price += get_cost_of_bush(arg) | 8 | total_price += cost_of_bush(arg) | ||
9 | 9 | ||||
10 | for kwarg_value in kwargs.values(): | 10 | for kwarg_value in kwargs.values(): | ||
11 | if isinstance(kwarg_value, dict): | 11 | if isinstance(kwarg_value, dict): | ||
n | 12 | if is_a_bush_validation(kwarg_value): | n | 12 | if is_bush(kwarg_value): |
13 | valid_bushes += 1 | 13 | valid_bushes = True | ||
14 | total_price += get_cost_of_bush(kwarg_value) | 14 | total_price += cost_of_bush(kwarg_value) | ||
15 | 15 | ||||
16 | output = generate_output(kwargs, total_price, valid_bushes) | 16 | output = generate_output(kwargs, total_price, valid_bushes) | ||
17 | return output | 17 | return output | ||
18 | 18 | ||||
19 | def generate_output(kwargs, total_price, valid_bushes): | 19 | def generate_output(kwargs, total_price, valid_bushes): | ||
20 | output_text = 'Ni!' | 20 | output_text = 'Ni!' | ||
n | 21 | if valid_bushes == 0: | n | 21 | if valid_bushes == False: |
22 | return(output_text) | 22 | return output_text | ||
23 | elif not one_that_looks_nice(kwargs, total_price) or is_too_expensive(total_price): | 23 | elif not one_that_looks_nice(kwargs, total_price) or is_too_expensive(total_price): | ||
n | 24 | return output_text | n | 24 | return output_text |
25 | else: | 25 | else: | ||
n | 26 | return (get_formated_price(total_price)) | n | 26 | return f'{total_price:.2f}лв' |
27 | 27 | ||||
n | n | 28 | def is_bush(arg): | ||
29 | key = 'name' | ||||
30 | return key in arg.keys() and str(arg[key]).lower() in ('храст', 'shrub', 'bush') | ||||
28 | 31 | ||||
n | 29 | def is_a_bush_validation(arg): | n | ||
30 | key = 'name' | ||||
31 | if key in arg.keys() and any(bush_values == str(arg[key]).lower() for bush_values in ['храст', 'shrub', 'bush']): | ||||
32 | return True | ||||
33 | else: | ||||
34 | return False | ||||
35 | |||||
36 | def get_cost_of_bush(arg): | 32 | def cost_of_bush(arg): | ||
37 | value = 'cost' | 33 | value = 'cost' | ||
38 | if value in arg.keys() and isinstance(arg[value], (int, float)): | 34 | if value in arg.keys() and isinstance(arg[value], (int, float)): | ||
39 | price = arg[value] | 35 | price = arg[value] | ||
40 | return price | 36 | return price | ||
n | 41 | else: | n | ||
42 | return 0 | 37 | return 0 | ||
43 | 38 | ||||
44 | def one_that_looks_nice(kwargs, price): | 39 | def one_that_looks_nice(kwargs, price): | ||
45 | whole_part_price = int(price) | 40 | whole_part_price = int(price) | ||
46 | if whole_part_price == 0: | 41 | if whole_part_price == 0: | ||
47 | return False | 42 | return False | ||
48 | if len(kwargs) == 0: | 43 | if len(kwargs) == 0: | ||
n | 49 | return 0 % whole_part_price == 0 | n | 44 | return True |
50 | elif kwargs: | 45 | elif kwargs: | ||
51 | unique_chars = set() | 46 | unique_chars = set() | ||
n | 52 | for kwarg_key,kwarg_value in kwargs.items(): | n | 47 | for kwarg_key, kwarg_value in kwargs.items(): |
53 | if(isinstance(kwarg_value, dict) and kwarg_value['name'] in ['храст', 'shrub', 'bush']): | 48 | if isinstance(kwarg_value, dict) and kwarg_value['name'] in ('храст', 'shrub', 'bush'): | ||
54 | unique_chars.update(kwarg_key) | 49 | unique_chars.update(kwarg_key) | ||
55 | unique_chars_count = len(unique_chars) | 50 | unique_chars_count = len(unique_chars) | ||
n | 56 | looks_nice = unique_chars_count % whole_part_price == 0 | n | 51 | looks_nice = unique_chars_count % whole_part_price == 0 |
57 | return looks_nice | 52 | return looks_nice | ||
58 | else: | 53 | else: | ||
n | 59 | return False | n | 54 | return False |
60 | 55 | ||||
61 | def is_too_expensive(price): | 56 | def is_too_expensive(price): | ||
t | 62 | if price > 42.00: | t | 57 | return price > 42.00 |
63 | return True | ||||
64 | return False | ||||
65 | |||||
66 | def get_formated_price(total_price): | ||||
67 | return f'{total_price:.2f}лв' | ||||
68 |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
n | 1 | def function_that_says_ni(*args,**kwargs): | n | 1 | def function_that_says_ni(*args, **kwargs): |
2 | total_price = 0 | 2 | total_price = 0 | ||
3 | valid_bushes = 0 | 3 | valid_bushes = 0 | ||
4 | for arg in args: | 4 | for arg in args: | ||
5 | if isinstance(arg, dict): | 5 | if isinstance(arg, dict): | ||
6 | if is_a_bush_validation(arg): | 6 | if is_a_bush_validation(arg): | ||
7 | valid_bushes += 1 | 7 | valid_bushes += 1 | ||
8 | total_price += get_cost_of_bush(arg) | 8 | total_price += get_cost_of_bush(arg) | ||
9 | 9 | ||||
10 | for kwarg_value in kwargs.values(): | 10 | for kwarg_value in kwargs.values(): | ||
11 | if isinstance(kwarg_value, dict): | 11 | if isinstance(kwarg_value, dict): | ||
12 | if is_a_bush_validation(kwarg_value): | 12 | if is_a_bush_validation(kwarg_value): | ||
13 | valid_bushes += 1 | 13 | valid_bushes += 1 | ||
14 | total_price += get_cost_of_bush(kwarg_value) | 14 | total_price += get_cost_of_bush(kwarg_value) | ||
15 | 15 | ||||
16 | output = generate_output(kwargs, total_price, valid_bushes) | 16 | output = generate_output(kwargs, total_price, valid_bushes) | ||
17 | return output | 17 | return output | ||
18 | 18 | ||||
19 | def generate_output(kwargs, total_price, valid_bushes): | 19 | def generate_output(kwargs, total_price, valid_bushes): | ||
20 | output_text = 'Ni!' | 20 | output_text = 'Ni!' | ||
21 | if valid_bushes == 0: | 21 | if valid_bushes == 0: | ||
22 | return(output_text) | 22 | return(output_text) | ||
n | 23 | elif not one_that_looks_nice(kwargs,total_price) or is_too_expensive(total_price): | n | 23 | elif not one_that_looks_nice(kwargs, total_price) or is_too_expensive(total_price): |
24 | return output_text | 24 | return output_text | ||
25 | else: | 25 | else: | ||
26 | return (get_formated_price(total_price)) | 26 | return (get_formated_price(total_price)) | ||
27 | 27 | ||||
28 | 28 | ||||
29 | def is_a_bush_validation(arg): | 29 | def is_a_bush_validation(arg): | ||
30 | key = 'name' | 30 | key = 'name' | ||
31 | if key in arg.keys() and any(bush_values == str(arg[key]).lower() for bush_values in ['храст', 'shrub', 'bush']): | 31 | if key in arg.keys() and any(bush_values == str(arg[key]).lower() for bush_values in ['храст', 'shrub', 'bush']): | ||
32 | return True | 32 | return True | ||
33 | else: | 33 | else: | ||
34 | return False | 34 | return False | ||
35 | 35 | ||||
36 | def get_cost_of_bush(arg): | 36 | def get_cost_of_bush(arg): | ||
37 | value = 'cost' | 37 | value = 'cost' | ||
t | 38 | if value in arg.keys() and isinstance(arg[value], (int,float)): | t | 38 | if value in arg.keys() and isinstance(arg[value], (int, float)): |
39 | price = arg[value] | 39 | price = arg[value] | ||
40 | return price | 40 | return price | ||
41 | else: | 41 | else: | ||
42 | return 0 | 42 | return 0 | ||
43 | 43 | ||||
44 | def one_that_looks_nice(kwargs, price): | 44 | def one_that_looks_nice(kwargs, price): | ||
45 | whole_part_price = int(price) | 45 | whole_part_price = int(price) | ||
46 | if whole_part_price == 0: | 46 | if whole_part_price == 0: | ||
47 | return False | 47 | return False | ||
48 | if len(kwargs) == 0: | 48 | if len(kwargs) == 0: | ||
49 | return 0 % whole_part_price == 0 | 49 | return 0 % whole_part_price == 0 | ||
50 | elif kwargs: | 50 | elif kwargs: | ||
51 | unique_chars = set() | 51 | unique_chars = set() | ||
52 | for kwarg_key,kwarg_value in kwargs.items(): | 52 | for kwarg_key,kwarg_value in kwargs.items(): | ||
53 | if(isinstance(kwarg_value, dict) and kwarg_value['name'] in ['храст', 'shrub', 'bush']): | 53 | if(isinstance(kwarg_value, dict) and kwarg_value['name'] in ['храст', 'shrub', 'bush']): | ||
54 | unique_chars.update(kwarg_key) | 54 | unique_chars.update(kwarg_key) | ||
55 | unique_chars_count = len(unique_chars) | 55 | unique_chars_count = len(unique_chars) | ||
56 | looks_nice = unique_chars_count % whole_part_price == 0 | 56 | looks_nice = unique_chars_count % whole_part_price == 0 | ||
57 | return looks_nice | 57 | return looks_nice | ||
58 | else: | 58 | else: | ||
59 | return False | 59 | return False | ||
60 | 60 | ||||
61 | def is_too_expensive(price): | 61 | def is_too_expensive(price): | ||
62 | if price > 42.00: | 62 | if price > 42.00: | ||
63 | return True | 63 | return True | ||
64 | return False | 64 | return False | ||
65 | 65 | ||||
66 | def get_formated_price(total_price): | 66 | def get_formated_price(total_price): | ||
67 | return f'{total_price:.2f}лв' | 67 | return f'{total_price:.2f}лв' | ||
68 | 68 |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|