1def get_dictionaries_from_arguments(*args, **kwargs):
2 dictionaries = []
3 for arg in args:
4 if type(arg) is dict:
5 dictionaries.append(arg)
6
7 for key, value in kwargs.items():
8 if type(value) is dict:
9 dictionaries.append(value)
10
11 return dictionaries
12
13
14
15def is_shrub(dictionary):
16 possible_bush_names = ["храст", "bush", "shrub"]
17 return "name" in dictionary and type(dictionary["name"]) is str and dictionary["name"].lower() in possible_bush_names
18
19
20
21def cost_of_shrubbery(shrubs):
22 cost = 0
23 for shrub in shrubs:
24 if shrub.get("cost"):
25 cost += shrub["cost"]
26 return cost
27
28
29
30def is_looking_nice(cost, **kwargs):
31 unique_letters = []
32 for key, value in kwargs.items():
33 for letter in key:
34 unique_letters.append(letter)
35 unique_letters = set(unique_letters)
36 return len(unique_letters) % int(cost) == 0
37
38
39
40def function_that_says_ni(*args, **kwargs):
41 dictionaries = get_dictionaries_from_arguments(*args, **kwargs)
42 shrubs = list(filter(is_shrub, dictionaries))
43 cost = cost_of_shrubbery(shrubs)
44 if cost > 42 or cost == 0:
45 return("Ni!")
46 else:
47 if is_looking_nice(cost, **kwargs):
48 return(f"{cost:.2f}лв")
49 else:
50 return("Ni!")
..E.......
======================================================================
ERROR: test_cost_whole_part_zero (test.TestNi.test_cost_whole_part_zero)
Test with a total cost part equal to zero.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 43, in test_cost_whole_part_zero
self.assertEqual(function_that_says_ni({'name': 'shrub', 'cost': 0.1},
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/solution.py", line 47, in function_that_says_ni
if is_looking_nice(cost, **kwargs):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/solution.py", line 36, in is_looking_nice
return len(unique_letters) % int(cost) == 0
~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
ZeroDivisionError: integer modulo by zero
----------------------------------------------------------------------
Ran 10 tests in 0.001s
FAILED (errors=1)
f | 1 | def get_dictionaries_from_arguments(*args, **kwargs): | f | 1 | def get_dictionaries_from_arguments(*args, **kwargs): |
2 | dictionaries = [] | 2 | dictionaries = [] | ||
3 | for arg in args: | 3 | for arg in args: | ||
4 | if type(arg) is dict: | 4 | if type(arg) is dict: | ||
5 | dictionaries.append(arg) | 5 | dictionaries.append(arg) | ||
n | 6 | n | |||
7 | 6 | ||||
8 | for key, value in kwargs.items(): | 7 | for key, value in kwargs.items(): | ||
9 | if type(value) is dict: | 8 | if type(value) is dict: | ||
10 | dictionaries.append(value) | 9 | dictionaries.append(value) | ||
11 | 10 | ||||
12 | return dictionaries | 11 | return dictionaries | ||
13 | 12 | ||||
14 | 13 | ||||
15 | 14 | ||||
16 | def is_shrub(dictionary): | 15 | def is_shrub(dictionary): | ||
n | 17 | if "name" in dictionary and( | n | 16 | possible_bush_names = ["храст", "bush", "shrub"] |
18 | type(dictionary["name"]) is str) and( | 17 | return "name" in dictionary and type(dictionary["name"]) is str and dictionary["name"].lower() in possible_bush_names | ||
19 | dictionary["name"].lower() == "храст" or | ||||
20 | dictionary["name"].lower() == "bush" or | ||||
21 | dictionary["name"].lower() == "shrub"): | ||||
22 | if "cost" not in dictionary: | ||||
23 | dictionary["cost"] = 0 | ||||
24 | return True | ||||
25 | return False | ||||
26 | 18 | ||||
27 | 19 | ||||
28 | 20 | ||||
29 | def cost_of_shrubbery(shrubs): | 21 | def cost_of_shrubbery(shrubs): | ||
30 | cost = 0 | 22 | cost = 0 | ||
31 | for shrub in shrubs: | 23 | for shrub in shrubs: | ||
n | n | 24 | if shrub.get("cost"): | ||
32 | cost += shrub["cost"] | 25 | cost += shrub["cost"] | ||
33 | return cost | 26 | return cost | ||
34 | 27 | ||||
35 | 28 | ||||
36 | 29 | ||||
n | 37 | def isLookingNice(cost, **kwargs): | n | 30 | def is_looking_nice(cost, **kwargs): |
38 | unique_letters = [] | 31 | unique_letters = [] | ||
39 | for key, value in kwargs.items(): | 32 | for key, value in kwargs.items(): | ||
40 | for letter in key: | 33 | for letter in key: | ||
41 | unique_letters.append(letter) | 34 | unique_letters.append(letter) | ||
42 | unique_letters = set(unique_letters) | 35 | unique_letters = set(unique_letters) | ||
n | 43 | if len(unique_letters) % int(cost) == 0: | n | 36 | return len(unique_letters) % int(cost) == 0 |
44 | return True | ||||
45 | return False | ||||
46 | 37 | ||||
47 | 38 | ||||
48 | 39 | ||||
49 | def function_that_says_ni(*args, **kwargs): | 40 | def function_that_says_ni(*args, **kwargs): | ||
50 | dictionaries = get_dictionaries_from_arguments(*args, **kwargs) | 41 | dictionaries = get_dictionaries_from_arguments(*args, **kwargs) | ||
51 | shrubs = list(filter(is_shrub, dictionaries)) | 42 | shrubs = list(filter(is_shrub, dictionaries)) | ||
52 | cost = cost_of_shrubbery(shrubs) | 43 | cost = cost_of_shrubbery(shrubs) | ||
n | 53 | if cost > 42.00 or cost == 0.00: | n | 44 | if cost > 42 or cost == 0: |
54 | print("Ni") | 45 | return("Ni!") | ||
55 | return 0 | ||||
56 | else: | 46 | else: | ||
n | 57 | if isLookingNice(cost, **kwargs): | n | 47 | if is_looking_nice(cost, **kwargs): |
58 | print(f"{cost:.2f}лв") | 48 | return(f"{cost:.2f}лв") | ||
59 | return 0 | ||||
60 | else: | 49 | else: | ||
t | 61 | print("Ni") | t | 50 | return("Ni!") |
62 | return 0 | 51 |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | def get_dictionaries_from_arguments(*args, **kwargs): | f | 1 | def get_dictionaries_from_arguments(*args, **kwargs): |
2 | dictionaries = [] | 2 | dictionaries = [] | ||
3 | for arg in args: | 3 | for arg in args: | ||
4 | if type(arg) is dict: | 4 | if type(arg) is dict: | ||
5 | dictionaries.append(arg) | 5 | dictionaries.append(arg) | ||
6 | 6 | ||||
7 | 7 | ||||
8 | for key, value in kwargs.items(): | 8 | for key, value in kwargs.items(): | ||
9 | if type(value) is dict: | 9 | if type(value) is dict: | ||
10 | dictionaries.append(value) | 10 | dictionaries.append(value) | ||
n | 11 | n | |||
12 | 11 | ||||
13 | return dictionaries | 12 | return dictionaries | ||
14 | 13 | ||||
15 | 14 | ||||
16 | 15 | ||||
17 | def is_shrub(dictionary): | 16 | def is_shrub(dictionary): | ||
18 | if "name" in dictionary and( | 17 | if "name" in dictionary and( | ||
19 | type(dictionary["name"]) is str) and( | 18 | type(dictionary["name"]) is str) and( | ||
20 | dictionary["name"].lower() == "храст" or | 19 | dictionary["name"].lower() == "храст" or | ||
21 | dictionary["name"].lower() == "bush" or | 20 | dictionary["name"].lower() == "bush" or | ||
22 | dictionary["name"].lower() == "shrub"): | 21 | dictionary["name"].lower() == "shrub"): | ||
23 | if "cost" not in dictionary: | 22 | if "cost" not in dictionary: | ||
24 | dictionary["cost"] = 0 | 23 | dictionary["cost"] = 0 | ||
25 | return True | 24 | return True | ||
26 | return False | 25 | return False | ||
27 | 26 | ||||
28 | 27 | ||||
29 | 28 | ||||
30 | def cost_of_shrubbery(shrubs): | 29 | def cost_of_shrubbery(shrubs): | ||
31 | cost = 0 | 30 | cost = 0 | ||
32 | for shrub in shrubs: | 31 | for shrub in shrubs: | ||
33 | cost += shrub["cost"] | 32 | cost += shrub["cost"] | ||
34 | return cost | 33 | return cost | ||
35 | 34 | ||||
36 | 35 | ||||
37 | 36 | ||||
38 | def isLookingNice(cost, **kwargs): | 37 | def isLookingNice(cost, **kwargs): | ||
39 | unique_letters = [] | 38 | unique_letters = [] | ||
40 | for key, value in kwargs.items(): | 39 | for key, value in kwargs.items(): | ||
41 | for letter in key: | 40 | for letter in key: | ||
42 | unique_letters.append(letter) | 41 | unique_letters.append(letter) | ||
43 | unique_letters = set(unique_letters) | 42 | unique_letters = set(unique_letters) | ||
44 | if len(unique_letters) % int(cost) == 0: | 43 | if len(unique_letters) % int(cost) == 0: | ||
45 | return True | 44 | return True | ||
46 | return False | 45 | return False | ||
47 | 46 | ||||
48 | 47 | ||||
49 | 48 | ||||
50 | def function_that_says_ni(*args, **kwargs): | 49 | def function_that_says_ni(*args, **kwargs): | ||
51 | dictionaries = get_dictionaries_from_arguments(*args, **kwargs) | 50 | dictionaries = get_dictionaries_from_arguments(*args, **kwargs) | ||
52 | shrubs = list(filter(is_shrub, dictionaries)) | 51 | shrubs = list(filter(is_shrub, dictionaries)) | ||
53 | cost = cost_of_shrubbery(shrubs) | 52 | cost = cost_of_shrubbery(shrubs) | ||
54 | if cost > 42.00 or cost == 0.00: | 53 | if cost > 42.00 or cost == 0.00: | ||
55 | print("Ni") | 54 | print("Ni") | ||
56 | return 0 | 55 | return 0 | ||
57 | else: | 56 | else: | ||
58 | if isLookingNice(cost, **kwargs): | 57 | if isLookingNice(cost, **kwargs): | ||
59 | print(f"{cost:.2f}лв") | 58 | print(f"{cost:.2f}лв") | ||
60 | return 0 | 59 | return 0 | ||
61 | else: | 60 | else: | ||
62 | print("Ni") | 61 | print("Ni") | ||
63 | return 0 | 62 | return 0 | ||
t | 64 | t | |||
65 | |||||
66 | |||||
67 | |||||
68 | # function_that_says_ni(123, "test", {"name": "bush", "cost": 2}, [1, 2, 3], my_bush = {"name": "sHrUb", "cost": 1}, my_not_bush = {"name": 3}, my_list = [1,2]) | ||||
69 | # function_that_says_ni({"name": "храст", "cost": 120}) | ||||
70 | # function_that_says_ni({"name": "храст", "cost": 1}) | ||||
71 | # function_that_says_ni(aabcc={"name": "bush", "cost": 3.20}) |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | def get_dictionaries_from_arguments(*args, **kwargs): | f | 1 | def get_dictionaries_from_arguments(*args, **kwargs): |
2 | dictionaries = [] | 2 | dictionaries = [] | ||
3 | for arg in args: | 3 | for arg in args: | ||
4 | if type(arg) is dict: | 4 | if type(arg) is dict: | ||
5 | dictionaries.append(arg) | 5 | dictionaries.append(arg) | ||
6 | 6 | ||||
7 | 7 | ||||
8 | for key, value in kwargs.items(): | 8 | for key, value in kwargs.items(): | ||
9 | if type(value) is dict: | 9 | if type(value) is dict: | ||
10 | dictionaries.append(value) | 10 | dictionaries.append(value) | ||
11 | 11 | ||||
12 | 12 | ||||
13 | return dictionaries | 13 | return dictionaries | ||
14 | 14 | ||||
15 | 15 | ||||
16 | 16 | ||||
17 | def is_shrub(dictionary): | 17 | def is_shrub(dictionary): | ||
18 | if "name" in dictionary and( | 18 | if "name" in dictionary and( | ||
19 | type(dictionary["name"]) is str) and( | 19 | type(dictionary["name"]) is str) and( | ||
20 | dictionary["name"].lower() == "храст" or | 20 | dictionary["name"].lower() == "храст" or | ||
21 | dictionary["name"].lower() == "bush" or | 21 | dictionary["name"].lower() == "bush" or | ||
22 | dictionary["name"].lower() == "shrub"): | 22 | dictionary["name"].lower() == "shrub"): | ||
23 | if "cost" not in dictionary: | 23 | if "cost" not in dictionary: | ||
24 | dictionary["cost"] = 0 | 24 | dictionary["cost"] = 0 | ||
25 | return True | 25 | return True | ||
26 | return False | 26 | return False | ||
27 | 27 | ||||
28 | 28 | ||||
29 | 29 | ||||
30 | def cost_of_shrubbery(shrubs): | 30 | def cost_of_shrubbery(shrubs): | ||
31 | cost = 0 | 31 | cost = 0 | ||
32 | for shrub in shrubs: | 32 | for shrub in shrubs: | ||
33 | cost += shrub["cost"] | 33 | cost += shrub["cost"] | ||
34 | return cost | 34 | return cost | ||
35 | 35 | ||||
36 | 36 | ||||
37 | 37 | ||||
38 | def isLookingNice(cost, **kwargs): | 38 | def isLookingNice(cost, **kwargs): | ||
39 | unique_letters = [] | 39 | unique_letters = [] | ||
40 | for key, value in kwargs.items(): | 40 | for key, value in kwargs.items(): | ||
41 | for letter in key: | 41 | for letter in key: | ||
42 | unique_letters.append(letter) | 42 | unique_letters.append(letter) | ||
43 | unique_letters = set(unique_letters) | 43 | unique_letters = set(unique_letters) | ||
44 | if len(unique_letters) % int(cost) == 0: | 44 | if len(unique_letters) % int(cost) == 0: | ||
45 | return True | 45 | return True | ||
46 | return False | 46 | return False | ||
47 | 47 | ||||
48 | 48 | ||||
49 | 49 | ||||
50 | def function_that_says_ni(*args, **kwargs): | 50 | def function_that_says_ni(*args, **kwargs): | ||
51 | dictionaries = get_dictionaries_from_arguments(*args, **kwargs) | 51 | dictionaries = get_dictionaries_from_arguments(*args, **kwargs) | ||
52 | shrubs = list(filter(is_shrub, dictionaries)) | 52 | shrubs = list(filter(is_shrub, dictionaries)) | ||
53 | cost = cost_of_shrubbery(shrubs) | 53 | cost = cost_of_shrubbery(shrubs) | ||
54 | if cost > 42.00 or cost == 0.00: | 54 | if cost > 42.00 or cost == 0.00: | ||
55 | print("Ni") | 55 | print("Ni") | ||
56 | return 0 | 56 | return 0 | ||
57 | else: | 57 | else: | ||
58 | if isLookingNice(cost, **kwargs): | 58 | if isLookingNice(cost, **kwargs): | ||
59 | print(f"{cost:.2f}лв") | 59 | print(f"{cost:.2f}лв") | ||
60 | return 0 | 60 | return 0 | ||
61 | else: | 61 | else: | ||
62 | print("Ni") | 62 | print("Ni") | ||
63 | return 0 | 63 | return 0 | ||
64 | 64 | ||||
65 | 65 | ||||
66 | 66 | ||||
67 | 67 | ||||
t | 68 | function_that_says_ni(123, "test", {"name": "bush", "cost": 2}, [1, 2, 3], my_bush = {"name": "sHrUb", "cost": 1}, my_not_bush = {"name": 3}, my_list = [1,2]) | t | 68 | # function_that_says_ni(123, "test", {"name": "bush", "cost": 2}, [1, 2, 3], my_bush = {"name": "sHrUb", "cost": 1}, my_not_bush = {"name": 3}, my_list = [1,2]) |
69 | function_that_says_ni({"name": "храст", "cost": 120}) | 69 | # function_that_says_ni({"name": "храст", "cost": 120}) | ||
70 | function_that_says_ni({"name": "храст", "cost": 1}) | 70 | # function_that_says_ni({"name": "храст", "cost": 1}) | ||
71 | function_that_says_ni(aabcc={"name": "bush", "cost": 3.20}) | 71 | # function_that_says_ni(aabcc={"name": "bush", "cost": 3.20}) |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|