1def function_that_says_ni(*args, **kwargs):
2 valid_names = {"храст", "shrub", "bush"}
3 total_cost = 0
4 unique_letters = set()
5
6 for arg in args:
7 if isinstance(arg, dict) and 'name' in arg:
8 name = arg['name'].lower()
9 if name in valid_names:
10 cost = arg.get('cost', 0)
11 if isinstance(cost, (int, float)):
12 total_cost += round(cost, 2)
13
14 for name, arg in kwargs.items():
15 if isinstance(arg, dict) and 'name' in arg:
16 shrub_name = arg['name'].lower()
17 if shrub_name in valid_names:
18 cost = arg.get('cost', 0)
19 if isinstance(cost, (int, float)):
20 total_cost += round(cost, 2)
21 unique_letters.update(name)
22
23 if total_cost > 42:
24 return "Ni!"
25
26 int_part_cost = int(total_cost)
27 if int_part_cost == 0 or len(unique_letters) % int_part_cost != 0:
28 return "Ni!"
29
30 return f"{total_cost:.2f}лв"
..........
----------------------------------------------------------------------
Ran 10 tests in 0.000s
OK
Георги Кунчев
22.10.2024 18:15Единствено бих обединил двата цикъла. Иначе нямам коментари.
|