1def function_that_says_ni(*args, **kwargs):
2 total_cost = 0
3 shrub_names = set()
4 valid_shrub_names = {"храст", "shrub", "bush"}
5
6 for arg in args:
7 if isinstance(arg, dict):
8 name = arg.get("name", "").lower()
9 cost = arg.get("cost", 0)
10 if name in valid_shrub_names:
11 total_cost += float(cost)
12
13 for key, value in kwargs.items():
14 if isinstance(value, dict):
15 name = value.get("name", "").lower()
16 cost = value.get("cost", 0)
17 if name in valid_shrub_names:
18 total_cost += float(cost)
19 shrub_names.update(set(key))
20
21 if total_cost > 42.00:
22 return "Ni!"
23
24 whole_part_of_cost = int(total_cost)
25
26 if whole_part_of_cost == 0 or len(shrub_names) % whole_part_of_cost != 0:
27 return "Ni!"
28
29 return f"{total_cost:.2f}лв"
..........
----------------------------------------------------------------------
Ran 10 tests in 0.000s
OK
Димитър Илиев
21.10.2024 10:21Благодаря за обратната връзка! Мисля да не рискувам и да видя твоето решението.
|
f | 1 | def function_that_says_ni(*args, **kwargs): | f | 1 | def function_that_says_ni(*args, **kwargs): |
n | 2 | total_cost = 0.0 | n | 2 | total_cost = 0 |
3 | shrub_names = set() | 3 | shrub_names = set() | ||
4 | valid_shrub_names = {"храст", "shrub", "bush"} | 4 | valid_shrub_names = {"храст", "shrub", "bush"} | ||
5 | 5 | ||||
6 | for arg in args: | 6 | for arg in args: | ||
7 | if isinstance(arg, dict): | 7 | if isinstance(arg, dict): | ||
8 | name = arg.get("name", "").lower() | 8 | name = arg.get("name", "").lower() | ||
9 | cost = arg.get("cost", 0) | 9 | cost = arg.get("cost", 0) | ||
10 | if name in valid_shrub_names: | 10 | if name in valid_shrub_names: | ||
11 | total_cost += float(cost) | 11 | total_cost += float(cost) | ||
12 | 12 | ||||
13 | for key, value in kwargs.items(): | 13 | for key, value in kwargs.items(): | ||
14 | if isinstance(value, dict): | 14 | if isinstance(value, dict): | ||
15 | name = value.get("name", "").lower() | 15 | name = value.get("name", "").lower() | ||
16 | cost = value.get("cost", 0) | 16 | cost = value.get("cost", 0) | ||
17 | if name in valid_shrub_names: | 17 | if name in valid_shrub_names: | ||
18 | total_cost += float(cost) | 18 | total_cost += float(cost) | ||
19 | shrub_names.update(set(key)) | 19 | shrub_names.update(set(key)) | ||
20 | 20 | ||||
21 | if total_cost > 42.00: | 21 | if total_cost > 42.00: | ||
22 | return "Ni!" | 22 | return "Ni!" | ||
23 | 23 | ||||
n | 24 | unique_letters_count = len(shrub_names) | n | ||
25 | whole_part_of_cost = int(total_cost) | 24 | whole_part_of_cost = int(total_cost) | ||
26 | 25 | ||||
t | 27 | if whole_part_of_cost == 0 or unique_letters_count % whole_part_of_cost != 0: | t | 26 | if whole_part_of_cost == 0 or len(shrub_names) % whole_part_of_cost != 0: |
28 | return "Ni!" | 27 | return "Ni!" | ||
29 | 28 | ||||
30 | return f"{total_cost:.2f}лв" | 29 | return f"{total_cost:.2f}лв" |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|