1def function_that_says_ni(*args, **kwargs):
2 shrub_dict = {'храст', '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 shrub_dict:
10 cost = arg.get('cost', 0)
11 if isinstance(cost, (int, float)):
12 total_cost += cost
13
14 for key, value in kwargs.items():
15 if isinstance(value, dict) and 'name' in value:
16 name = value['name'].lower()
17 if name in shrub_dict:
18 unique_letters.update(key)
19 cost = value.get('cost', 0)
20 if isinstance(cost, (int, float)):
21 total_cost += cost
22
23 if total_cost > 42.00:
24 return "Ni!"
25
26 if int(total_cost) == 0 or len(unique_letters) % int(total_cost) != 0:
27 return "Ni!"
28
29 return f"{total_cost:.2f}лв"
..........
----------------------------------------------------------------------
Ran 10 tests in 0.000s
OK
Георги Кунчев
20.10.2024 11:48Като изключим, че можеш да се опиташ да обединиш двата цикъла, тък като са доста сходни, нямам коментари. Добро решение!
|
21.10.2024 14:13