1NAMES = ["храст", "shrub", "bush"]
2NI = "Ni!"
3
4
5def function_that_says_ni(*args, **kwargs):
6
7 lst_valid_bushes = []
8 st_unique_symbols_used = set()
9 price = 0
10
11 for arg in args:
12 if "name" in arg and arg["name"].lower() in NAMES:
13 lst_valid_bushes.append(arg)
14
15 if "cost" in arg:
16 price += arg["cost"]
17
18 for kwarg in kwargs:
19 if "name" in kwargs[kwarg] and kwargs[kwarg]["name"].lower() in NAMES:
20 lst_valid_bushes.append(kwargs[kwarg])
21
22 if "cost" in kwargs[kwarg]:
23 price += kwargs[kwarg]["cost"]
24
25 for char in kwarg:
26 st_unique_symbols_used.add(char)
27
28 if len(lst_valid_bushes) == 0:
29 return NI
30
31 lenght = len(st_unique_symbols_used)
32 floor = int(price)
33
34 if lenght != 0:
35 rest = floor / lenght
36 if not rest.is_integer():
37 return NI
38
39 if price > 42.00:
40 return NI
41
42 return f"{price:.2f}лв"
..F.F..E.F
======================================================================
ERROR: test_other_than_dicts (test.TestNi.test_other_than_dicts)
Test with inputs other than dicts.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 74, in test_other_than_dicts
self.assertEqual(function_that_says_ni(1, 3.14, ['some_list'], some_arg={1, 2, 3}), self.NI)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/solution.py", line 12, in function_that_says_ni
if "name" in arg and arg["name"].lower() in NAMES:
^^^^^^^^^^^^^
TypeError: argument of type 'int' is not iterable
======================================================================
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!
======================================================================
FAIL: test_invalid_strings (test.TestNi.test_invalid_strings)
Test with invalid strings that might be misinterpreted.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 69, in test_invalid_strings
self.assertEqual(function_that_says_ni({'name': 'shrub', ' cost': 1}), self.NI) # Space before cost
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: '0.00лв' != 'Ni!'
- 0.00лв
+ Ni!
======================================================================
FAIL: test_with_no_cost (test.TestNi.test_with_no_cost)
Test with a shrub without defined cost.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 30, in test_with_no_cost
self.assertEqual(function_that_says_ni({'name': 'shrub'}), self.NI)
AssertionError: '0.00лв' != 'Ni!'
- 0.00лв
+ Ni!
----------------------------------------------------------------------
Ran 10 tests in 0.001s
FAILED (failures=3, errors=1)
n | 1 | import math | n | ||
2 | |||||
3 | NAMES = ["храст", "shrub", "bush"] | 1 | NAMES = ["храст", "shrub", "bush"] | ||
4 | NI = "Ni!" | 2 | NI = "Ni!" | ||
5 | 3 | ||||
6 | 4 | ||||
7 | def function_that_says_ni(*args, **kwargs): | 5 | def function_that_says_ni(*args, **kwargs): | ||
8 | 6 | ||||
n | 9 | lst = [] | n | 7 | lst_valid_bushes = [] |
10 | st = set() | 8 | st_unique_symbols_used = set() | ||
11 | price = 0 | 9 | price = 0 | ||
12 | 10 | ||||
13 | for arg in args: | 11 | for arg in args: | ||
14 | if "name" in arg and arg["name"].lower() in NAMES: | 12 | if "name" in arg and arg["name"].lower() in NAMES: | ||
n | 15 | lst.append(arg) | n | 13 | lst_valid_bushes.append(arg) |
16 | 14 | ||||
17 | if "cost" in arg: | 15 | if "cost" in arg: | ||
18 | price += arg["cost"] | 16 | price += arg["cost"] | ||
19 | 17 | ||||
20 | for kwarg in kwargs: | 18 | for kwarg in kwargs: | ||
21 | if "name" in kwargs[kwarg] and kwargs[kwarg]["name"].lower() in NAMES: | 19 | if "name" in kwargs[kwarg] and kwargs[kwarg]["name"].lower() in NAMES: | ||
n | 22 | lst.append(kwargs[kwarg]) | n | 20 | lst_valid_bushes.append(kwargs[kwarg]) |
23 | 21 | ||||
24 | if "cost" in kwargs[kwarg]: | 22 | if "cost" in kwargs[kwarg]: | ||
25 | price += kwargs[kwarg]["cost"] | 23 | price += kwargs[kwarg]["cost"] | ||
26 | 24 | ||||
27 | for char in kwarg: | 25 | for char in kwarg: | ||
n | 28 | st.add(char) | n | 26 | st_unique_symbols_used.add(char) |
29 | 27 | ||||
n | 30 | if len(lst) == 0: | n | 28 | if len(lst_valid_bushes) == 0: |
31 | return NI | 29 | return NI | ||
32 | 30 | ||||
n | 33 | lenght = len(st) | n | 31 | lenght = len(st_unique_symbols_used) |
34 | floor = math.floor(price) | 32 | floor = int(price) | ||
35 | 33 | ||||
36 | if lenght != 0: | 34 | if lenght != 0: | ||
37 | rest = floor / lenght | 35 | rest = floor / lenght | ||
t | 38 | if not (rest).is_integer(): | t | 36 | if not rest.is_integer(): |
39 | return NI | 37 | return NI | ||
40 | 38 | ||||
41 | if price > 42.00: | 39 | if price > 42.00: | ||
42 | return NI | 40 | return NI | ||
43 | 41 | ||||
44 | return f"{price:.2f}лв" | 42 | return f"{price:.2f}лв" |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | import math | f | 1 | import math |
2 | 2 | ||||
n | 3 | NAMES = ['храст', 'shrub', 'bush'] | n | 3 | NAMES = ["храст", "shrub", "bush"] |
4 | NI = 'Ni!' | 4 | NI = "Ni!" | ||
5 | |||||
5 | 6 | ||||
6 | def function_that_says_ni(*args, **kwargs): | 7 | def function_that_says_ni(*args, **kwargs): | ||
7 | 8 | ||||
8 | lst = [] | 9 | lst = [] | ||
9 | st = set() | 10 | st = set() | ||
10 | price = 0 | 11 | price = 0 | ||
11 | 12 | ||||
12 | for arg in args: | 13 | for arg in args: | ||
n | 13 | if 'name' in arg and arg["name"].lower() in NAMES: | n | 14 | if "name" in arg and arg["name"].lower() in NAMES: |
14 | lst.append(arg) | 15 | lst.append(arg) | ||
15 | 16 | ||||
n | 16 | if 'cost' in arg: | n | 17 | if "cost" in arg: |
17 | price += arg['cost'] | 18 | price += arg["cost"] | ||
18 | 19 | ||||
19 | for kwarg in kwargs: | 20 | for kwarg in kwargs: | ||
n | 20 | if 'name' in kwargs[kwarg] and kwargs[kwarg]["name"].lower() in NAMES: | n | 21 | if "name" in kwargs[kwarg] and kwargs[kwarg]["name"].lower() in NAMES: |
21 | lst.append(kwargs[kwarg]) | 22 | lst.append(kwargs[kwarg]) | ||
22 | 23 | ||||
t | 23 | if 'cost' in kwargs[kwarg]: | t | 24 | if "cost" in kwargs[kwarg]: |
24 | price += kwargs[kwarg]['cost'] | 25 | price += kwargs[kwarg]["cost"] | ||
25 | 26 | ||||
26 | for char in kwarg: | 27 | for char in kwarg: | ||
27 | st.add(char) | 28 | st.add(char) | ||
28 | 29 | ||||
29 | if len(lst) == 0: | 30 | if len(lst) == 0: | ||
30 | return NI | 31 | return NI | ||
31 | 32 | ||||
32 | lenght = len(st) | 33 | lenght = len(st) | ||
33 | floor = math.floor(price) | 34 | floor = math.floor(price) | ||
34 | 35 | ||||
35 | if lenght != 0: | 36 | if lenght != 0: | ||
36 | rest = floor / lenght | 37 | rest = floor / lenght | ||
37 | if not (rest).is_integer(): | 38 | if not (rest).is_integer(): | ||
38 | return NI | 39 | return NI | ||
39 | 40 | ||||
40 | if price > 42.00: | 41 | if price > 42.00: | ||
41 | return NI | 42 | return NI | ||
42 | 43 | ||||
43 | return f"{price:.2f}лв" | 44 | return f"{price:.2f}лв" |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
t | 1 | import math | t | 1 | import math |
2 | 2 | ||||
3 | NAMES = ['храст', 'shrub', 'bush'] | 3 | NAMES = ['храст', 'shrub', 'bush'] | ||
4 | NI = 'Ni!' | 4 | NI = 'Ni!' | ||
5 | 5 | ||||
6 | def function_that_says_ni(*args, **kwargs): | 6 | def function_that_says_ni(*args, **kwargs): | ||
7 | 7 | ||||
8 | lst = [] | 8 | lst = [] | ||
9 | st = set() | 9 | st = set() | ||
10 | price = 0 | 10 | price = 0 | ||
11 | 11 | ||||
12 | for arg in args: | 12 | for arg in args: | ||
13 | if 'name' in arg and arg["name"].lower() in NAMES: | 13 | if 'name' in arg and arg["name"].lower() in NAMES: | ||
14 | lst.append(arg) | 14 | lst.append(arg) | ||
15 | 15 | ||||
16 | if 'cost' in arg: | 16 | if 'cost' in arg: | ||
17 | price += arg['cost'] | 17 | price += arg['cost'] | ||
18 | 18 | ||||
19 | for kwarg in kwargs: | 19 | for kwarg in kwargs: | ||
20 | if 'name' in kwargs[kwarg] and kwargs[kwarg]["name"].lower() in NAMES: | 20 | if 'name' in kwargs[kwarg] and kwargs[kwarg]["name"].lower() in NAMES: | ||
21 | lst.append(kwargs[kwarg]) | 21 | lst.append(kwargs[kwarg]) | ||
22 | 22 | ||||
23 | if 'cost' in kwargs[kwarg]: | 23 | if 'cost' in kwargs[kwarg]: | ||
24 | price += kwargs[kwarg]['cost'] | 24 | price += kwargs[kwarg]['cost'] | ||
25 | 25 | ||||
26 | for char in kwarg: | 26 | for char in kwarg: | ||
27 | st.add(char) | 27 | st.add(char) | ||
28 | 28 | ||||
29 | if len(lst) == 0: | 29 | if len(lst) == 0: | ||
30 | return NI | 30 | return NI | ||
31 | 31 | ||||
32 | lenght = len(st) | 32 | lenght = len(st) | ||
33 | floor = math.floor(price) | 33 | floor = math.floor(price) | ||
34 | 34 | ||||
35 | if lenght != 0: | 35 | if lenght != 0: | ||
36 | rest = floor / lenght | 36 | rest = floor / lenght | ||
37 | if not (rest).is_integer(): | 37 | if not (rest).is_integer(): | ||
38 | return NI | 38 | return NI | ||
39 | 39 | ||||
40 | if price > 42.00: | 40 | if price > 42.00: | ||
41 | return NI | 41 | return NI | ||
42 | 42 | ||||
43 | return f"{price:.2f}лв" | 43 | return f"{price:.2f}лв" |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|