1def function_that_says_ni(*args, **kwargs):
2
3 bush_names = ("храст", "shrub", "bush")
4 result = dict.fromkeys(bush_names, 0)
5 total = 0
6
7 for arg in args:
8 if type(arg) is not dict:
9 continue
10 else:
11 arg = dict(arg)
12
13 if "name" in arg:
14 name = str.lower(arg["name"])
15 else:
16 continue
17
18 if name not in bush_names:
19 continue
20
21 price = 0
22
23 if "cost" in arg:
24 price = arg["cost"]
25
26 total += price
27 result[name] +=1
28
29 all_var_names = ""
30
31 for kwarg in kwargs:
32
33 if type(kwargs[kwarg]) is not dict:
34 continue
35 else:
36 potential_bush = kwargs[kwarg]
37 if "name" in potential_bush:
38 name = str.lower(potential_bush["name"])
39 else:
40 continue
41
42 price = 0
43 if name not in bush_names:
44 continue
45
46 if "cost" in potential_bush:
47 price = potential_bush["cost"]
48
49 all_var_names += kwarg
50
51 total += price
52 result[name] += 1
53
54
55 unique_letters = set(all_var_names)
56 ul_count = len(unique_letters)
57 int_part_of_price = int(total // 1)
58
59 if int_part_of_price != 0:
60 if ul_count % int_part_of_price != 0:
61 return "Ni!"
62
63 total = format(total, '.2f')
64
65 if float(total) > 42:
66 return "Ni!"
67
68 ctr = 0
69 for bush in bush_names:
70 ctr += result[bush]
71
72 if ctr == 0:
73 return "Ni!"
74
75 if int_part_of_price == 0:
76 return "Ni!"
77
78 return total + "лв"
..........
----------------------------------------------------------------------
Ran 10 tests in 0.000s
OK
Георги Кунчев
21.10.2024 10:29Бъди по-пестелив с използването на празни редове в тялото на функциите си. Не е грешно да имаш нови редове, но PEP8 казва да сме пестеливи, а в твоята версия има 30 празни реда и 47 използвани.
Можеш да слагаш празни редове, за да отделиш логически блокове, но не прекалявай.
|
21.10.2024 10:19
21.10.2024 10:19
21.10.2024 10:20
21.10.2024 10:22
21.10.2024 10:22
21.10.2024 10:23
21.10.2024 10:26