1def function_that_says_ni(*args, **kwargs):
2 valid_keys = ("bush", "shrub", "храст") # added tuple with valid keywords
3 cost = 0.0
4 kwargs_names = []
5 unique_letters = set()
6
7 for arg in args:
8 if type(arg) == dict:
9 name = arg.get("name")
10 if name is not None:
11 if type(name) == str:
12 name = name.lower()
13 if name in valid_keys:
14 # corrected without additional if-check
15 cost += arg.get("cost", 0)
16
17 for key, value in kwargs.items():
18 if type(value) == dict:
19 name = value.get("name")
20 if name is not None:
21 if type(name) == str:
22 name = name.lower()
23 if name in valid_keys:
24 kwargs_names.append(key)
25 # corrected without additional if-check
26 cost += value.get("cost", 0)
27
28 for name in kwargs_names:
29 # corrected using built-in method
30 unique_letters.update(name)
31
32 unique_letters_count = len(unique_letters)
33 whole_part = int(cost)
34
35 if cost <= 42.0 and whole_part > 0:
36 if unique_letters_count % whole_part == 0:
37 # corrected return
38 return f"{cost:.2f}лв"
39
40 return "Ni!"
..........
----------------------------------------------------------------------
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): |
n | 2 | valid_keys = ("bush", "shrub", "храст") | n | 2 | valid_keys = ("bush", "shrub", "храст") # added tuple with valid keywords |
3 | cost = 0.0 | 3 | cost = 0.0 | ||
4 | kwargs_names = [] | 4 | kwargs_names = [] | ||
5 | unique_letters = set() | 5 | unique_letters = set() | ||
6 | 6 | ||||
7 | for arg in args: | 7 | for arg in args: | ||
8 | if type(arg) == dict: | 8 | if type(arg) == dict: | ||
9 | name = arg.get("name") | 9 | name = arg.get("name") | ||
10 | if name is not None: | 10 | if name is not None: | ||
11 | if type(name) == str: | 11 | if type(name) == str: | ||
12 | name = name.lower() | 12 | name = name.lower() | ||
13 | if name in valid_keys: | 13 | if name in valid_keys: | ||
n | n | 14 | # corrected without additional if-check | ||
14 | cost += arg.get("cost", 0) | 15 | cost += arg.get("cost", 0) | ||
15 | 16 | ||||
16 | for key, value in kwargs.items(): | 17 | for key, value in kwargs.items(): | ||
17 | if type(value) == dict: | 18 | if type(value) == dict: | ||
18 | name = value.get("name") | 19 | name = value.get("name") | ||
19 | if name is not None: | 20 | if name is not None: | ||
20 | if type(name) == str: | 21 | if type(name) == str: | ||
21 | name = name.lower() | 22 | name = name.lower() | ||
22 | if name in valid_keys: | 23 | if name in valid_keys: | ||
23 | kwargs_names.append(key) | 24 | kwargs_names.append(key) | ||
n | n | 25 | # corrected without additional if-check | ||
24 | cost += value.get("cost", 0) | 26 | cost += value.get("cost", 0) | ||
25 | 27 | ||||
26 | for name in kwargs_names: | 28 | for name in kwargs_names: | ||
n | n | 29 | # corrected using built-in method | ||
27 | unique_letters.update(name) | 30 | unique_letters.update(name) | ||
28 | 31 | ||||
29 | unique_letters_count = len(unique_letters) | 32 | unique_letters_count = len(unique_letters) | ||
30 | whole_part = int(cost) | 33 | whole_part = int(cost) | ||
31 | 34 | ||||
32 | if cost <= 42.0 and whole_part > 0: | 35 | if cost <= 42.0 and whole_part > 0: | ||
33 | if unique_letters_count % whole_part == 0: | 36 | if unique_letters_count % whole_part == 0: | ||
n | n | 37 | # corrected return | ||
34 | return f"{cost:.2f}лв" | 38 | return f"{cost:.2f}лв" | ||
35 | 39 | ||||
36 | return "Ni!" | 40 | return "Ni!" | ||
t | 37 | t |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | def function_that_says_ni(*args, **kwargs): | f | 1 | def function_that_says_ni(*args, **kwargs): |
n | 2 | is_shrub = False #"храсталак" | n | 2 | valid_keys = ("bush", "shrub", "храст") |
3 | cost = 0.0 | 3 | cost = 0.0 | ||
4 | kwargs_names = [] | 4 | kwargs_names = [] | ||
5 | unique_letters = set() | 5 | unique_letters = set() | ||
6 | 6 | ||||
7 | for arg in args: | 7 | for arg in args: | ||
8 | if type(arg) == dict: | 8 | if type(arg) == dict: | ||
9 | name = arg.get("name") | 9 | name = arg.get("name") | ||
10 | if name is not None: | 10 | if name is not None: | ||
11 | if type(name) == str: | 11 | if type(name) == str: | ||
12 | name = name.lower() | 12 | name = name.lower() | ||
n | 13 | if name == "bush" or name == "shrub" or name == "храст": | n | 13 | if name in valid_keys: |
14 | if arg.get("cost") is not None: | ||||
15 | cost += arg.get("cost") | 14 | cost += arg.get("cost", 0) | ||
16 | 15 | ||||
17 | for key, value in kwargs.items(): | 16 | for key, value in kwargs.items(): | ||
18 | if type(value) == dict: | 17 | if type(value) == dict: | ||
19 | name = value.get("name") | 18 | name = value.get("name") | ||
20 | if name is not None: | 19 | if name is not None: | ||
21 | if type(name) == str: | 20 | if type(name) == str: | ||
22 | name = name.lower() | 21 | name = name.lower() | ||
n | 23 | if name == "bush" or name == "shrub" or name == "храст": | n | 22 | if name in valid_keys: |
24 | kwargs_names.append(key) | 23 | kwargs_names.append(key) | ||
n | 25 | if value.get("cost") is not None: | n | ||
26 | cost += value.get("cost") | 24 | cost += value.get("cost", 0) | ||
27 | 25 | ||||
28 | for name in kwargs_names: | 26 | for name in kwargs_names: | ||
n | 29 | for char in name: | n | ||
30 | unique_letters.add(char) | 27 | unique_letters.update(name) | ||
31 | 28 | ||||
32 | unique_letters_count = len(unique_letters) | 29 | unique_letters_count = len(unique_letters) | ||
33 | whole_part = int(cost) | 30 | whole_part = int(cost) | ||
34 | 31 | ||||
35 | if cost <= 42.0 and whole_part > 0: | 32 | if cost <= 42.0 and whole_part > 0: | ||
36 | if unique_letters_count % whole_part == 0: | 33 | if unique_letters_count % whole_part == 0: | ||
n | 37 | is_shrub = True | n | 34 | return f"{cost:.2f}лв" |
38 | 35 | ||||
t | 39 | if not is_shrub: | t | ||
40 | return "Ni!" | 36 | return "Ni!" | ||
41 | else: | 37 | |||
42 | return f"{cost:.2f}лв" |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|