1def function_that_says_ni(*args, **kwargs):
2
3 sum_of_costs = 0
4 bushes = ("храст", "bush", "shrub")
5 all_names = ""
6
7 for arg in args:
8 if type(arg) is dict and "name" in arg:
9 if arg["name"].lower() in bushes:
10 sum_of_costs += arg.get("cost", 0)
11
12 for arg in kwargs:
13 if type(kwargs[arg]) is dict:
14 value = kwargs[arg]
15 if "name" in value and value["name"].lower() in bushes:
16 sum_of_costs += value.get("cost", 0)
17 all_names += arg
18
19 integer_cost = int(sum_of_costs)
20 number_of_unique_characters = len(set(all_names))
21
22 if integer_cost == 0:
23 return "Ni!"
24 if sum_of_costs > 42:
25 return "Ni!"
26 if number_of_unique_characters % (int(sum_of_costs)) != 0:
27 return "Ni!"
28
29 return f"{sum_of_costs:.2f}лв"
..........
----------------------------------------------------------------------
Ran 10 tests in 0.000s
OK
f | 1 | def function_that_says_ni(*args, **kwargs): | f | 1 | def function_that_says_ni(*args, **kwargs): |
2 | 2 | ||||
3 | sum_of_costs = 0 | 3 | sum_of_costs = 0 | ||
4 | bushes = ("храст", "bush", "shrub") | 4 | bushes = ("храст", "bush", "shrub") | ||
5 | all_names = "" | 5 | all_names = "" | ||
6 | 6 | ||||
7 | for arg in args: | 7 | for arg in args: | ||
8 | if type(arg) is dict and "name" in arg: | 8 | if type(arg) is dict and "name" in arg: | ||
9 | if arg["name"].lower() in bushes: | 9 | if arg["name"].lower() in bushes: | ||
n | 10 | sum_of_costs = sum_of_costs + arg.get("cost", 0) | n | 10 | sum_of_costs += arg.get("cost", 0) |
11 | else: | ||||
12 | continue | ||||
13 | else: | ||||
14 | continue | ||||
15 | 11 | ||||
16 | for arg in kwargs: | 12 | for arg in kwargs: | ||
17 | if type(kwargs[arg]) is dict: | 13 | if type(kwargs[arg]) is dict: | ||
18 | value = kwargs[arg] | 14 | value = kwargs[arg] | ||
19 | if "name" in value and value["name"].lower() in bushes: | 15 | if "name" in value and value["name"].lower() in bushes: | ||
n | 20 | sum_of_costs = sum_of_costs + value.get("cost", 0) | n | 16 | sum_of_costs += value.get("cost", 0) |
21 | all_names = all_names + arg | 17 | all_names += arg | ||
22 | else: | ||||
23 | continue | ||||
24 | else: | ||||
25 | continue | ||||
26 | 18 | ||||
27 | integer_cost = int(sum_of_costs) | 19 | integer_cost = int(sum_of_costs) | ||
28 | number_of_unique_characters = len(set(all_names)) | 20 | number_of_unique_characters = len(set(all_names)) | ||
29 | 21 | ||||
n | 30 | if integer_cost is 0: | n | 22 | if integer_cost == 0: |
31 | return "Ni!" | 23 | return "Ni!" | ||
32 | if sum_of_costs > 42: | 24 | if sum_of_costs > 42: | ||
33 | return "Ni!" | 25 | return "Ni!" | ||
t | 34 | if number_of_unique_characters % (int(sum_of_costs)) is not 0: | t | 26 | if number_of_unique_characters % (int(sum_of_costs)) != 0: |
35 | return "Ni!" | 27 | return "Ni!" | ||
36 | 28 | ||||
37 | return f"{sum_of_costs:.2f}лв" | 29 | return f"{sum_of_costs:.2f}лв" |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|