1def function_that_says_ni (*args, **kwargs):
2 unique_characters = set()
3 total_price = 0.0
4 is_atleast_single_bush_added = False
5 is_good = False
6
7 for argument in args:
8 if type(argument) == dict:
9 if argument.get("name") is not None and argument.get("name").lower() in ["храст", "shrub", "bush"]:
10 is_atleast_single_bush_added = True
11 if type(argument.get("cost")) == int or type(argument.get("cost")) == float:
12 total_price += argument.get("cost")
13
14 for key, argument in kwargs.items():
15 if type(argument) == dict:
16 if argument.get("name") is not None and argument.get("name").lower() in ["храст", "shrub", "bush"]:
17 is_atleast_single_bush_added = True
18 if type(argument.get("cost")) == int or type(argument.get("cost")) == float:
19 total_price += argument.get("cost")
20 for character in key:
21 unique_characters.add(character)
22
23 if not total_price == 0 and len(unique_characters) % int(total_price) == 0:
24 is_good = True
25
26 if not is_atleast_single_bush_added:
27 return "Ni!"
28 elif total_price >= 42.0 or total_price <= 0.0 or not is_good:
29 return "Ni!"
30
31 return "{:.2f}".format(total_price) + "лв"
..E..F....
======================================================================
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 23, in function_that_says_ni
if not total_price == 0 and len(unique_characters) % int(total_price) == 0:
~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
ZeroDivisionError: integer modulo by zero
======================================================================
FAIL: test_multiple_shrubs_sumс (test.TestNi.test_multiple_shrubs_sumс)
Test with a multiple shrubs and cornercase costs.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 34, in test_multiple_shrubs_sumс
self.assertEqual(function_that_says_ni({'name': 'shrub', 'cost': 20.00},
AssertionError: 'Ni!' != '42.00лв'
- Ni!
+ 42.00лв
----------------------------------------------------------------------
Ran 10 tests in 0.001s
FAILED (failures=1, errors=1)
22.10.2024 18:39
22.10.2024 18:40
22.10.2024 18:41
22.10.2024 18:40
22.10.2024 18:41
22.10.2024 18:42