1def function_that_says_ni(*args, **kwargs):
2 храсталак = []
3 total_cost = 0
4 unique_letters = set()
5
6 def помощна_функция(potential_храст):
7 nonlocal total_cost
8 if type(potential_храст) is dict and potential_храст["name"].lower() in ["храст", "shrub", "bush"]:
9 if "cost" not in potential_храст:
10 potential_храст["cost"] = 0
11 else:
12 total_cost+=potential_храст["cost"]
13 храсталак.append(potential_храст)
14 return True
15 else:
16 return False
17
18 for potential in args:
19 помощна_функция(potential)
20
21 for key, potential in kwargs.items():
22 if помощна_функция(potential):
23 unique_letters.update(key)
24
25 if total_cost > 42 or int(total_cost) == 0 or len(unique_letters) % int(total_cost) != 0:
26 return "Ni!"
27
28 return f"{total_cost:.2f}лв"
....E.....
======================================================================
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 19, in function_that_says_ni
помощна_функция(potential)
File "/tmp/solution.py", line 8, in помощна_функция
if type(potential_храст) is dict and potential_храст["name"].lower() in ["храст", "shrub", "bush"]:
~~~~~~~~~~~~~~~^^^^^^^^
KeyError: 'name'
----------------------------------------------------------------------
Ran 10 tests in 0.001s
FAILED (errors=1)
17.10.2024 12:16
17.10.2024 12:18
17.10.2024 12:19