1BUSH_NAMES = ["храст", "shrub", "bush"]
2MAX_ACCEPTABLE_PRICE = 42.00
3KNIGHT_MESSAGE = "Ni!"
4
5def is_bush(bush_candidate):
6 if type(bush_candidate) != dict:
7 return False
8 if "name" not in bush_candidate.keys():
9 return False
10 if bush_candidate["name"].lower() not in BUSH_NAMES:
11 return False
12 return True
13
14def function_that_says_ni(*args, **kwargs):
15 cost_of_bushes = 0.0
16 used_letters = set()
17 has_bushes = False
18
19 for potential_bush in args:
20 if is_bush(potential_bush):
21 cost_of_bushes += potential_bush.get("cost", 0)
22 has_bushes = True
23
24 for bush_name, potential_bush in kwargs.items():
25 if is_bush(potential_bush):
26 cost_of_bushes += potential_bush.get("cost", 0)
27 has_bushes = True
28 used_letters.update(bush_name)
29
30 if not has_bushes:
31 return KNIGHT_MESSAGE
32 if cost_of_bushes > MAX_ACCEPTABLE_PRICE:
33 return KNIGHT_MESSAGE
34 if int(cost_of_bushes) == 0:
35 return KNIGHT_MESSAGE
36 if len(used_letters) % int(cost_of_bushes) != 0:
37 return KNIGHT_MESSAGE
38 return f"{cost_of_bushes:.2f}лв"
..........
----------------------------------------------------------------------
Ran 10 tests in 0.000s
OK
22.10.2024 11:13
22.10.2024 11:14
22.10.2024 11:14