1def function_that_says_ni(*args, **kwargs):
2 potential_bushes = []
3 named_arguments_bushes = ""
4 for position_argument in args:
5 if type(position_argument) is dict:
6 potential_bushes.append(position_argument)
7
8 for name, named_argument in kwargs.items():
9 if type(named_argument) is dict:
10 potential_bushes.append(named_argument)
11 named_arguments_bushes += name
12
13 potential_ni_bushes = []
14 for dictionary in potential_bushes:
15 for key, value in dictionary.items():
16 if key == 'name' and value.lower() in ["храст", "shrub", "bush"]:
17 potential_ni_bushes.append(dictionary)
18
19 bush_price = 0
20 not_too_expensive = False
21 is_nice = False
22 for dictionary in potential_ni_bushes:
23 for key, value in dictionary.items():
24 if key == 'cost' and (type(value) is int or type(value) is float):
25 bush_price += value
26
27 if bush_price <= 42.0:
28 not_too_expensive = True
29
30 if not_too_expensive:
31 if (len(set(named_arguments_bushes))) % int(bush_price) == 0:
32 is_nice = True
33
34 if is_nice and not_too_expensive:
35 return f"{float(bush_price):.2f}лв"
36 return "Ni!"
..EEE..E.E
======================================================================
ERROR: 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},
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/solution.py", line 31, in function_that_says_ni
if (len(set(named_arguments_bushes))) % int(bush_price) == 0:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
ZeroDivisionError: integer modulo by zero
======================================================================
ERROR: test_empty (test.TestNi.test_empty)
Test with empty input.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 13, in test_empty
self.assertEqual(function_that_says_ni(), self.NI)
^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/solution.py", line 31, in function_that_says_ni
if (len(set(named_arguments_bushes))) % int(bush_price) == 0:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
ZeroDivisionError: integer modulo by zero
======================================================================
ERROR: 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 67, in test_invalid_strings
self.assertEqual(function_that_says_ni({'no_name': 'bush', 'cost': 1}), self.NI)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/solution.py", line 31, in function_that_says_ni
if (len(set(named_arguments_bushes))) % int(bush_price) == 0:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
ZeroDivisionError: integer modulo by zero
======================================================================
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 31, in function_that_says_ni
if (len(set(named_arguments_bushes))) % int(bush_price) == 0:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
ZeroDivisionError: integer modulo by zero
======================================================================
ERROR: 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)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/solution.py", line 31, in function_that_says_ni
if (len(set(named_arguments_bushes))) % int(bush_price) == 0:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
ZeroDivisionError: integer modulo by zero
----------------------------------------------------------------------
Ran 10 tests in 0.002s
FAILED (errors=5)
f | 1 | def function_that_says_ni(*args, **kwargs): | f | 1 | def function_that_says_ni(*args, **kwargs): |
2 | potential_bushes = [] | 2 | potential_bushes = [] | ||
3 | named_arguments_bushes = "" | 3 | named_arguments_bushes = "" | ||
4 | for position_argument in args: | 4 | for position_argument in args: | ||
5 | if type(position_argument) is dict: | 5 | if type(position_argument) is dict: | ||
6 | potential_bushes.append(position_argument) | 6 | potential_bushes.append(position_argument) | ||
n | n | 7 | |||
7 | for name, named_argument in kwargs.items(): | 8 | for name, named_argument in kwargs.items(): | ||
8 | if type(named_argument) is dict: | 9 | if type(named_argument) is dict: | ||
9 | potential_bushes.append(named_argument) | 10 | potential_bushes.append(named_argument) | ||
10 | named_arguments_bushes += name | 11 | named_arguments_bushes += name | ||
n | n | 12 | |||
11 | potential_ni_bushes = [] | 13 | potential_ni_bushes = [] | ||
12 | for dictionary in potential_bushes: | 14 | for dictionary in potential_bushes: | ||
n | 13 | for key,value in dictionary.items(): | n | 15 | for key, value in dictionary.items(): |
14 | if key == 'name' and value.lower() in ["храст", "shrub", "bush"]: | 16 | if key == 'name' and value.lower() in ["храст", "shrub", "bush"]: | ||
15 | potential_ni_bushes.append(dictionary) | 17 | potential_ni_bushes.append(dictionary) | ||
n | n | 18 | |||
16 | bush_price = 0 | 19 | bush_price = 0 | ||
17 | not_too_expensive = False | 20 | not_too_expensive = False | ||
18 | is_nice = False | 21 | is_nice = False | ||
19 | for dictionary in potential_ni_bushes: | 22 | for dictionary in potential_ni_bushes: | ||
n | 20 | for key,value in dictionary.items(): | n | 23 | for key, value in dictionary.items(): |
21 | if key == 'cost' and (type(value) is int or type(value) is float): | 24 | if key == 'cost' and (type(value) is int or type(value) is float): | ||
22 | bush_price += value | 25 | bush_price += value | ||
n | n | 26 | |||
23 | if bush_price <= 42.0: | 27 | if bush_price <= 42.0: | ||
24 | not_too_expensive = True | 28 | not_too_expensive = True | ||
n | n | 29 | |||
25 | if not_too_expensive: | 30 | if not_too_expensive: | ||
n | 26 | if (len(set(named_arguments_bushes)))%int(bush_price) == 0: | n | 31 | if (len(set(named_arguments_bushes))) % int(bush_price) == 0: |
27 | is_nice = True | 32 | is_nice = True | ||
n | n | 33 | |||
28 | if is_nice and not_too_expensive: | 34 | if is_nice and not_too_expensive: | ||
29 | return f"{float(bush_price):.2f}лв" | 35 | return f"{float(bush_price):.2f}лв" | ||
t | 30 | return "Ni" | t | 36 | return "Ni!" |
31 |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | def function_that_says_ni(*args, **kwargs): | f | 1 | def function_that_says_ni(*args, **kwargs): |
2 | potential_bushes = [] | 2 | potential_bushes = [] | ||
3 | named_arguments_bushes = "" | 3 | named_arguments_bushes = "" | ||
4 | for position_argument in args: | 4 | for position_argument in args: | ||
5 | if type(position_argument) is dict: | 5 | if type(position_argument) is dict: | ||
6 | potential_bushes.append(position_argument) | 6 | potential_bushes.append(position_argument) | ||
7 | for name, named_argument in kwargs.items(): | 7 | for name, named_argument in kwargs.items(): | ||
8 | if type(named_argument) is dict: | 8 | if type(named_argument) is dict: | ||
9 | potential_bushes.append(named_argument) | 9 | potential_bushes.append(named_argument) | ||
10 | named_arguments_bushes += name | 10 | named_arguments_bushes += name | ||
11 | potential_ni_bushes = [] | 11 | potential_ni_bushes = [] | ||
12 | for dictionary in potential_bushes: | 12 | for dictionary in potential_bushes: | ||
13 | for key,value in dictionary.items(): | 13 | for key,value in dictionary.items(): | ||
14 | if key == 'name' and value.lower() in ["храст", "shrub", "bush"]: | 14 | if key == 'name' and value.lower() in ["храст", "shrub", "bush"]: | ||
15 | potential_ni_bushes.append(dictionary) | 15 | potential_ni_bushes.append(dictionary) | ||
16 | bush_price = 0 | 16 | bush_price = 0 | ||
17 | not_too_expensive = False | 17 | not_too_expensive = False | ||
18 | is_nice = False | 18 | is_nice = False | ||
19 | for dictionary in potential_ni_bushes: | 19 | for dictionary in potential_ni_bushes: | ||
20 | for key,value in dictionary.items(): | 20 | for key,value in dictionary.items(): | ||
21 | if key == 'cost' and (type(value) is int or type(value) is float): | 21 | if key == 'cost' and (type(value) is int or type(value) is float): | ||
22 | bush_price += value | 22 | bush_price += value | ||
23 | if bush_price <= 42.0: | 23 | if bush_price <= 42.0: | ||
24 | not_too_expensive = True | 24 | not_too_expensive = True | ||
25 | if not_too_expensive: | 25 | if not_too_expensive: | ||
26 | if (len(set(named_arguments_bushes)))%int(bush_price) == 0: | 26 | if (len(set(named_arguments_bushes)))%int(bush_price) == 0: | ||
27 | is_nice = True | 27 | is_nice = True | ||
28 | if is_nice and not_too_expensive: | 28 | if is_nice and not_too_expensive: | ||
29 | return f"{float(bush_price):.2f}лв" | 29 | return f"{float(bush_price):.2f}лв" | ||
30 | return "Ni" | 30 | return "Ni" | ||
31 | 31 | ||||
t | 32 | print(function_that_says_ni({"name": "храст", "cost": 120})) | t | ||
33 | print(function_that_says_ni({"name": "храст", "cost": 1})) | ||||
34 | print(function_that_says_ni(aabcc={"name": "bush", "cost": 3.20})) |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|