1def function_that_says_ni(*args, **kwargs):
2 if not there_is_a_shrub(*args, **kwargs):
3 return "Ni!"
4 elif not is_one_that_looks_nice(*args, **kwargs):
5 return "Ni!"
6 else:
7 total_cost = get_cost_from_args(*args,**kwargs)
8 return f"{total_cost:.2f}лв"
9
10
11def there_is_a_shrub(*args, **kwargs):
12 for curr_name in args:
13 if "name" in curr_name and is_shrub(curr_name["name"]):
14 return True
15 for curr_dict in kwargs.values():
16 if "name" in curr_dict and is_shrub(curr_dict["name"]):
17 return True
18
19 return False
20
21def get_cost_from_args(*args, **kwargs):
22 total = 0
23 for current_dict in *args, *kwargs.values():
24 if not isDict(current_dict):
25 continue
26 if "cost" in current_dict and current_dict["cost"] and is_shrub(current_dict["name"]):
27 total += float(current_dict["cost"])
28 return total
29
30def is_one_that_looks_nice(*args, **kwargs):
31 total_cost = float(get_cost_from_args(*args, **kwargs))
32 if is_too_expensive(total_cost):
33 return False
34 diff_letters = get_diff_letters_from_named_args(**kwargs)
35 if not price_by_letters_check(diff_letters, total_cost):
36 return False
37 return True
38
39def price_by_letters_check(diff_letters, price):
40 integer = int(price)
41 if price == 0.00 and diff_letters > 0:
42 return False
43 if diff_letters == 0 or integer % diff_letters == 0:
44 return True
45 return False
46
47def get_diff_letters_from_named_args(**kwargs):
48 diff_letters = []
49 for current_string in kwargs:
50 curr_lower = current_string.lower()
51 for current_letter in curr_lower:
52 if current_letter not in diff_letters:
53 diff_letters.append(current_letter)
54
55 return len(diff_letters)
56
57def is_too_expensive(price):
58 return price > 42
59
60def is_shrub(name):
61 name_lower = name.lower()
62 return name_lower in ("shrub", "храст", "bush")
63
64def isDict(argument):
65 return type(argument) == dict
66
..F.F..E.F
======================================================================
ERROR: test_other_than_dicts (test.TestNi.test_other_than_dicts)
Test with inputs other than dicts.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 74, in test_other_than_dicts
self.assertEqual(function_that_says_ni(1, 3.14, ['some_list'], some_arg={1, 2, 3}), self.NI)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/solution.py", line 2, in function_that_says_ni
if not there_is_a_shrub(*args, **kwargs):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/solution.py", line 13, in there_is_a_shrub
if "name" in curr_name and is_shrub(curr_name["name"]):
^^^^^^^^^^^^^^^^^^^
TypeError: argument of type 'int' is not iterable
======================================================================
FAIL: 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},
AssertionError: '0.30лв' != 'Ni!'
- 0.30лв
+ Ni!
======================================================================
FAIL: test_invalid_strings (test.TestNi.test_invalid_strings)
Test with invalid strings that might be misinterpreted.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 69, in test_invalid_strings
self.assertEqual(function_that_says_ni({'name': 'shrub', ' cost': 1}), self.NI) # Space before cost
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: '0.00лв' != 'Ni!'
- 0.00лв
+ Ni!
======================================================================
FAIL: test_with_no_cost (test.TestNi.test_with_no_cost)
Test with a shrub without defined cost.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 30, in test_with_no_cost
self.assertEqual(function_that_says_ni({'name': 'shrub'}), self.NI)
AssertionError: '0.00лв' != 'Ni!'
- 0.00лв
+ Ni!
----------------------------------------------------------------------
Ran 10 tests in 0.002s
FAILED (failures=3, errors=1)
| t | 1 | def function_that_says_ni(*args, **kwargs): | t | 1 | def function_that_says_ni(*args, **kwargs): |
| 2 | if not there_is_a_shrub(*args, **kwargs): | 2 | if not there_is_a_shrub(*args, **kwargs): | ||
| 3 | return "Ni!" | 3 | return "Ni!" | ||
| 4 | elif not is_one_that_looks_nice(*args, **kwargs): | 4 | elif not is_one_that_looks_nice(*args, **kwargs): | ||
| 5 | return "Ni!" | 5 | return "Ni!" | ||
| 6 | else: | 6 | else: | ||
| 7 | total_cost = get_cost_from_args(*args,**kwargs) | 7 | total_cost = get_cost_from_args(*args,**kwargs) | ||
| 8 | return f"{total_cost:.2f}лв" | 8 | return f"{total_cost:.2f}лв" | ||
| 9 | 9 | ||||
| 10 | 10 | ||||
| 11 | def there_is_a_shrub(*args, **kwargs): | 11 | def there_is_a_shrub(*args, **kwargs): | ||
| 12 | for curr_name in args: | 12 | for curr_name in args: | ||
| 13 | if "name" in curr_name and is_shrub(curr_name["name"]): | 13 | if "name" in curr_name and is_shrub(curr_name["name"]): | ||
| 14 | return True | 14 | return True | ||
| 15 | for curr_dict in kwargs.values(): | 15 | for curr_dict in kwargs.values(): | ||
| 16 | if "name" in curr_dict and is_shrub(curr_dict["name"]): | 16 | if "name" in curr_dict and is_shrub(curr_dict["name"]): | ||
| 17 | return True | 17 | return True | ||
| 18 | 18 | ||||
| 19 | return False | 19 | return False | ||
| 20 | 20 | ||||
| 21 | def get_cost_from_args(*args, **kwargs): | 21 | def get_cost_from_args(*args, **kwargs): | ||
| 22 | total = 0 | 22 | total = 0 | ||
| 23 | for current_dict in *args, *kwargs.values(): | 23 | for current_dict in *args, *kwargs.values(): | ||
| 24 | if not isDict(current_dict): | 24 | if not isDict(current_dict): | ||
| 25 | continue | 25 | continue | ||
| 26 | if "cost" in current_dict and current_dict["cost"] and is_shrub(current_dict["name"]): | 26 | if "cost" in current_dict and current_dict["cost"] and is_shrub(current_dict["name"]): | ||
| 27 | total += float(current_dict["cost"]) | 27 | total += float(current_dict["cost"]) | ||
| 28 | return total | 28 | return total | ||
| 29 | 29 | ||||
| 30 | def is_one_that_looks_nice(*args, **kwargs): | 30 | def is_one_that_looks_nice(*args, **kwargs): | ||
| 31 | total_cost = float(get_cost_from_args(*args, **kwargs)) | 31 | total_cost = float(get_cost_from_args(*args, **kwargs)) | ||
| 32 | if is_too_expensive(total_cost): | 32 | if is_too_expensive(total_cost): | ||
| 33 | return False | 33 | return False | ||
| 34 | diff_letters = get_diff_letters_from_named_args(**kwargs) | 34 | diff_letters = get_diff_letters_from_named_args(**kwargs) | ||
| 35 | if not price_by_letters_check(diff_letters, total_cost): | 35 | if not price_by_letters_check(diff_letters, total_cost): | ||
| 36 | return False | 36 | return False | ||
| 37 | return True | 37 | return True | ||
| 38 | 38 | ||||
| 39 | def price_by_letters_check(diff_letters, price): | 39 | def price_by_letters_check(diff_letters, price): | ||
| 40 | integer = int(price) | 40 | integer = int(price) | ||
| 41 | if price == 0.00 and diff_letters > 0: | 41 | if price == 0.00 and diff_letters > 0: | ||
| 42 | return False | 42 | return False | ||
| 43 | if diff_letters == 0 or integer % diff_letters == 0: | 43 | if diff_letters == 0 or integer % diff_letters == 0: | ||
| 44 | return True | 44 | return True | ||
| 45 | return False | 45 | return False | ||
| 46 | 46 | ||||
| 47 | def get_diff_letters_from_named_args(**kwargs): | 47 | def get_diff_letters_from_named_args(**kwargs): | ||
| 48 | diff_letters = [] | 48 | diff_letters = [] | ||
| 49 | for current_string in kwargs: | 49 | for current_string in kwargs: | ||
| 50 | curr_lower = current_string.lower() | 50 | curr_lower = current_string.lower() | ||
| 51 | for current_letter in curr_lower: | 51 | for current_letter in curr_lower: | ||
| 52 | if current_letter not in diff_letters: | 52 | if current_letter not in diff_letters: | ||
| 53 | diff_letters.append(current_letter) | 53 | diff_letters.append(current_letter) | ||
| 54 | 54 | ||||
| 55 | return len(diff_letters) | 55 | return len(diff_letters) | ||
| 56 | 56 | ||||
| 57 | def is_too_expensive(price): | 57 | def is_too_expensive(price): | ||
| 58 | return price > 42 | 58 | return price > 42 | ||
| 59 | 59 | ||||
| 60 | def is_shrub(name): | 60 | def is_shrub(name): | ||
| 61 | name_lower = name.lower() | 61 | name_lower = name.lower() | ||
| 62 | return name_lower in ("shrub", "храст", "bush") | 62 | return name_lower in ("shrub", "храст", "bush") | ||
| 63 | 63 | ||||
| 64 | def isDict(argument): | 64 | def isDict(argument): | ||
| 65 | return type(argument) == dict | 65 | return type(argument) == dict | ||
| 66 | 66 |
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||
| t | 1 | def function_that_says_ni(*args, **kwargs): | t | 1 | def function_that_says_ni(*args, **kwargs): |
| 2 | if not there_is_a_shrub(*args, **kwargs): | 2 | if not there_is_a_shrub(*args, **kwargs): | ||
| 3 | return "Ni!" | 3 | return "Ni!" | ||
| 4 | elif not is_one_that_looks_nice(*args, **kwargs): | 4 | elif not is_one_that_looks_nice(*args, **kwargs): | ||
| 5 | return "Ni!" | 5 | return "Ni!" | ||
| 6 | else: | 6 | else: | ||
| 7 | total_cost = get_cost_from_args(*args,**kwargs) | 7 | total_cost = get_cost_from_args(*args,**kwargs) | ||
| 8 | return f"{total_cost:.2f}лв" | 8 | return f"{total_cost:.2f}лв" | ||
| 9 | 9 | ||||
| 10 | 10 | ||||
| 11 | def there_is_a_shrub(*args, **kwargs): | 11 | def there_is_a_shrub(*args, **kwargs): | ||
| 12 | for curr_name in args: | 12 | for curr_name in args: | ||
| 13 | if "name" in curr_name and is_shrub(curr_name["name"]): | 13 | if "name" in curr_name and is_shrub(curr_name["name"]): | ||
| 14 | return True | 14 | return True | ||
| 15 | for curr_dict in kwargs.values(): | 15 | for curr_dict in kwargs.values(): | ||
| 16 | if "name" in curr_dict and is_shrub(curr_dict["name"]): | 16 | if "name" in curr_dict and is_shrub(curr_dict["name"]): | ||
| 17 | return True | 17 | return True | ||
| 18 | 18 | ||||
| 19 | return False | 19 | return False | ||
| 20 | 20 | ||||
| 21 | def get_cost_from_args(*args, **kwargs): | 21 | def get_cost_from_args(*args, **kwargs): | ||
| 22 | total = 0 | 22 | total = 0 | ||
| 23 | for current_dict in *args, *kwargs.values(): | 23 | for current_dict in *args, *kwargs.values(): | ||
| 24 | if not isDict(current_dict): | 24 | if not isDict(current_dict): | ||
| 25 | continue | 25 | continue | ||
| 26 | if "cost" in current_dict and current_dict["cost"] and is_shrub(current_dict["name"]): | 26 | if "cost" in current_dict and current_dict["cost"] and is_shrub(current_dict["name"]): | ||
| 27 | total += float(current_dict["cost"]) | 27 | total += float(current_dict["cost"]) | ||
| 28 | return total | 28 | return total | ||
| 29 | 29 | ||||
| 30 | def is_one_that_looks_nice(*args, **kwargs): | 30 | def is_one_that_looks_nice(*args, **kwargs): | ||
| 31 | total_cost = float(get_cost_from_args(*args, **kwargs)) | 31 | total_cost = float(get_cost_from_args(*args, **kwargs)) | ||
| 32 | if is_too_expensive(total_cost): | 32 | if is_too_expensive(total_cost): | ||
| 33 | return False | 33 | return False | ||
| 34 | diff_letters = get_diff_letters_from_named_args(**kwargs) | 34 | diff_letters = get_diff_letters_from_named_args(**kwargs) | ||
| 35 | if not price_by_letters_check(diff_letters, total_cost): | 35 | if not price_by_letters_check(diff_letters, total_cost): | ||
| 36 | return False | 36 | return False | ||
| 37 | return True | 37 | return True | ||
| 38 | 38 | ||||
| 39 | def price_by_letters_check(diff_letters, price): | 39 | def price_by_letters_check(diff_letters, price): | ||
| 40 | integer = int(price) | 40 | integer = int(price) | ||
| 41 | if price == 0.00 and diff_letters > 0: | 41 | if price == 0.00 and diff_letters > 0: | ||
| 42 | return False | 42 | return False | ||
| 43 | if diff_letters == 0 or integer % diff_letters == 0: | 43 | if diff_letters == 0 or integer % diff_letters == 0: | ||
| 44 | return True | 44 | return True | ||
| 45 | return False | 45 | return False | ||
| 46 | 46 | ||||
| 47 | def get_diff_letters_from_named_args(**kwargs): | 47 | def get_diff_letters_from_named_args(**kwargs): | ||
| 48 | diff_letters = [] | 48 | diff_letters = [] | ||
| 49 | for current_string in kwargs: | 49 | for current_string in kwargs: | ||
| 50 | curr_lower = current_string.lower() | 50 | curr_lower = current_string.lower() | ||
| 51 | for current_letter in curr_lower: | 51 | for current_letter in curr_lower: | ||
| 52 | if current_letter not in diff_letters: | 52 | if current_letter not in diff_letters: | ||
| 53 | diff_letters.append(current_letter) | 53 | diff_letters.append(current_letter) | ||
| 54 | 54 | ||||
| 55 | return len(diff_letters) | 55 | return len(diff_letters) | ||
| 56 | 56 | ||||
| 57 | def is_too_expensive(price): | 57 | def is_too_expensive(price): | ||
| 58 | return price > 42 | 58 | return price > 42 | ||
| 59 | 59 | ||||
| 60 | def is_shrub(name): | 60 | def is_shrub(name): | ||
| 61 | name_lower = name.lower() | 61 | name_lower = name.lower() | ||
| 62 | return name_lower in ("shrub", "храст", "bush") | 62 | return name_lower in ("shrub", "храст", "bush") | ||
| 63 | 63 | ||||
| 64 | def isDict(argument): | 64 | def isDict(argument): | ||
| 65 | return type(argument) == dict | 65 | return type(argument) == dict | ||
| 66 | 66 |
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||
| f | 1 | def function_that_says_ni(*args, **kwargs): | f | 1 | def function_that_says_ni(*args, **kwargs): |
| 2 | if not there_is_a_shrub(*args, **kwargs): | 2 | if not there_is_a_shrub(*args, **kwargs): | ||
| 3 | return "Ni!" | 3 | return "Ni!" | ||
| 4 | elif not is_one_that_looks_nice(*args, **kwargs): | 4 | elif not is_one_that_looks_nice(*args, **kwargs): | ||
| 5 | return "Ni!" | 5 | return "Ni!" | ||
| 6 | else: | 6 | else: | ||
| 7 | total_cost = get_cost_from_args(*args,**kwargs) | 7 | total_cost = get_cost_from_args(*args,**kwargs) | ||
| 8 | return f"{total_cost:.2f}лв" | 8 | return f"{total_cost:.2f}лв" | ||
| 9 | 9 | ||||
| 10 | 10 | ||||
| 11 | def there_is_a_shrub(*args, **kwargs): | 11 | def there_is_a_shrub(*args, **kwargs): | ||
| 12 | for curr_name in args: | 12 | for curr_name in args: | ||
| 13 | if "name" in curr_name and is_shrub(curr_name["name"]): | 13 | if "name" in curr_name and is_shrub(curr_name["name"]): | ||
| 14 | return True | 14 | return True | ||
| 15 | for curr_dict in kwargs.values(): | 15 | for curr_dict in kwargs.values(): | ||
| 16 | if "name" in curr_dict and is_shrub(curr_dict["name"]): | 16 | if "name" in curr_dict and is_shrub(curr_dict["name"]): | ||
| 17 | return True | 17 | return True | ||
| 18 | 18 | ||||
| 19 | return False | 19 | return False | ||
| 20 | 20 | ||||
| 21 | def get_cost_from_args(*args, **kwargs): | 21 | def get_cost_from_args(*args, **kwargs): | ||
| 22 | total = 0 | 22 | total = 0 | ||
| 23 | for current_dict in *args, *kwargs.values(): | 23 | for current_dict in *args, *kwargs.values(): | ||
| 24 | if not isDict(current_dict): | 24 | if not isDict(current_dict): | ||
| 25 | continue | 25 | continue | ||
| 26 | if "cost" in current_dict and current_dict["cost"] and is_shrub(current_dict["name"]): | 26 | if "cost" in current_dict and current_dict["cost"] and is_shrub(current_dict["name"]): | ||
| 27 | total += float(current_dict["cost"]) | 27 | total += float(current_dict["cost"]) | ||
| 28 | return total | 28 | return total | ||
| 29 | 29 | ||||
| 30 | def is_one_that_looks_nice(*args, **kwargs): | 30 | def is_one_that_looks_nice(*args, **kwargs): | ||
| 31 | total_cost = float(get_cost_from_args(*args, **kwargs)) | 31 | total_cost = float(get_cost_from_args(*args, **kwargs)) | ||
| 32 | if is_too_expensive(total_cost): | 32 | if is_too_expensive(total_cost): | ||
| 33 | return False | 33 | return False | ||
| 34 | diff_letters = get_diff_letters_from_named_args(**kwargs) | 34 | diff_letters = get_diff_letters_from_named_args(**kwargs) | ||
| 35 | if not price_by_letters_check(diff_letters, total_cost): | 35 | if not price_by_letters_check(diff_letters, total_cost): | ||
| 36 | return False | 36 | return False | ||
| 37 | return True | 37 | return True | ||
| 38 | 38 | ||||
| 39 | def price_by_letters_check(diff_letters, price): | 39 | def price_by_letters_check(diff_letters, price): | ||
| 40 | integer = int(price) | 40 | integer = int(price) | ||
| 41 | if price == 0.00 and diff_letters > 0: | 41 | if price == 0.00 and diff_letters > 0: | ||
| 42 | return False | 42 | return False | ||
| 43 | if diff_letters == 0 or integer % diff_letters == 0: | 43 | if diff_letters == 0 or integer % diff_letters == 0: | ||
| 44 | return True | 44 | return True | ||
| 45 | return False | 45 | return False | ||
| 46 | 46 | ||||
| 47 | def get_diff_letters_from_named_args(**kwargs): | 47 | def get_diff_letters_from_named_args(**kwargs): | ||
| 48 | diff_letters = [] | 48 | diff_letters = [] | ||
| 49 | for current_string in kwargs: | 49 | for current_string in kwargs: | ||
| 50 | curr_lower = current_string.lower() | 50 | curr_lower = current_string.lower() | ||
| 51 | for current_letter in curr_lower: | 51 | for current_letter in curr_lower: | ||
| 52 | if current_letter not in diff_letters: | 52 | if current_letter not in diff_letters: | ||
| 53 | diff_letters.append(current_letter) | 53 | diff_letters.append(current_letter) | ||
| 54 | 54 | ||||
| 55 | return len(diff_letters) | 55 | return len(diff_letters) | ||
| 56 | 56 | ||||
| 57 | def is_too_expensive(price): | 57 | def is_too_expensive(price): | ||
| 58 | return price > 42 | 58 | return price > 42 | ||
| 59 | 59 | ||||
| 60 | def is_shrub(name): | 60 | def is_shrub(name): | ||
| 61 | name_lower = name.lower() | 61 | name_lower = name.lower() | ||
| 62 | return name_lower in ("shrub", "храст", "bush") | 62 | return name_lower in ("shrub", "храст", "bush") | ||
| 63 | 63 | ||||
| 64 | def isDict(argument): | 64 | def isDict(argument): | ||
| 65 | return type(argument) == dict | 65 | return type(argument) == dict | ||
| 66 | 66 | ||||
| t | 67 | print(function_that_says_ni({"name": "храст", "cost": 1})) | t |
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||
| f | 1 | def function_that_says_ni(*args, **kwargs): | f | 1 | def function_that_says_ni(*args, **kwargs): |
| 2 | if not there_is_a_shrub(*args, **kwargs): | 2 | if not there_is_a_shrub(*args, **kwargs): | ||
| n | 3 | return "Ni" | n | 3 | return "Ni!" |
| 4 | elif not is_one_that_looks_nice(*args, **kwargs): | 4 | elif not is_one_that_looks_nice(*args, **kwargs): | ||
| n | 5 | return "Ni" | n | 5 | return "Ni!" |
| 6 | else: | 6 | else: | ||
| 7 | total_cost = get_cost_from_args(*args,**kwargs) | 7 | total_cost = get_cost_from_args(*args,**kwargs) | ||
| 8 | return f"{total_cost:.2f}лв" | 8 | return f"{total_cost:.2f}лв" | ||
| 9 | 9 | ||||
| 10 | 10 | ||||
| 11 | def there_is_a_shrub(*args, **kwargs): | 11 | def there_is_a_shrub(*args, **kwargs): | ||
| n | 12 | inKwargs = False | n | ||
| 13 | inArgs =False | ||||
| 14 | for curr_name in args: | 12 | for curr_name in args: | ||
| 15 | if "name" in curr_name and is_shrub(curr_name["name"]): | 13 | if "name" in curr_name and is_shrub(curr_name["name"]): | ||
| n | 16 | inArgs = True | n | 14 | return True |
| 17 | for curr_dict in kwargs.values(): | 15 | for curr_dict in kwargs.values(): | ||
| 18 | if "name" in curr_dict and is_shrub(curr_dict["name"]): | 16 | if "name" in curr_dict and is_shrub(curr_dict["name"]): | ||
| n | 19 | inKwargs = True | n | ||
| 20 | if inArgs or inKwargs: | ||||
| 21 | return True | 17 | return True | ||
| 18 | |||||
| 22 | return False | 19 | return False | ||
| 23 | 20 | ||||
| 24 | def get_cost_from_args(*args, **kwargs): | 21 | def get_cost_from_args(*args, **kwargs): | ||
| 25 | total = 0 | 22 | total = 0 | ||
| n | 26 | for current_dict in args: | n | 23 | for current_dict in *args, *kwargs.values(): |
| 27 | if not isDict(current_dict): | 24 | if not isDict(current_dict): | ||
| 28 | continue | 25 | continue | ||
| 29 | if "cost" in current_dict and current_dict["cost"] and is_shrub(current_dict["name"]): | 26 | if "cost" in current_dict and current_dict["cost"] and is_shrub(current_dict["name"]): | ||
| n | 30 | total+= float(current_dict["cost"]) | n | 27 | total += float(current_dict["cost"]) |
| 31 | for named_dict in kwargs.values(): | ||||
| 32 | if not isDict(named_dict): | ||||
| 33 | continue | ||||
| 34 | if "cost" in named_dict and named_dict["cost"] and is_shrub(named_dict["name"]): | ||||
| 35 | total+= float(named_dict["cost"]) | ||||
| 36 | return total | 28 | return total | ||
| 37 | 29 | ||||
| 38 | def is_one_that_looks_nice(*args, **kwargs): | 30 | def is_one_that_looks_nice(*args, **kwargs): | ||
| 39 | total_cost = float(get_cost_from_args(*args, **kwargs)) | 31 | total_cost = float(get_cost_from_args(*args, **kwargs)) | ||
| 40 | if is_too_expensive(total_cost): | 32 | if is_too_expensive(total_cost): | ||
| 41 | return False | 33 | return False | ||
| 42 | diff_letters = get_diff_letters_from_named_args(**kwargs) | 34 | diff_letters = get_diff_letters_from_named_args(**kwargs) | ||
| n | 43 | if not price_by_letters_check(diff_letters,total_cost): | n | 35 | if not price_by_letters_check(diff_letters, total_cost): |
| 44 | return False | 36 | return False | ||
| 45 | return True | 37 | return True | ||
| 46 | 38 | ||||
| n | 47 | def price_by_letters_check(diff_letters,price): | n | 39 | def price_by_letters_check(diff_letters, price): |
| 48 | integer= int(price) | 40 | integer = int(price) | ||
| 49 | if diff_letters == 0: | ||||
| 50 | return True | ||||
| 51 | if price == 0.00 and diff_letters>0: | 41 | if price == 0.00 and diff_letters > 0: | ||
| 52 | return False | 42 | return False | ||
| n | 53 | if integer % diff_letters == 0: | n | 43 | if diff_letters == 0 or integer % diff_letters == 0: |
| 54 | return True | 44 | return True | ||
| 55 | return False | 45 | return False | ||
| 56 | 46 | ||||
| 57 | def get_diff_letters_from_named_args(**kwargs): | 47 | def get_diff_letters_from_named_args(**kwargs): | ||
| 58 | diff_letters = [] | 48 | diff_letters = [] | ||
| 59 | for current_string in kwargs: | 49 | for current_string in kwargs: | ||
| 60 | curr_lower = current_string.lower() | 50 | curr_lower = current_string.lower() | ||
| 61 | for current_letter in curr_lower: | 51 | for current_letter in curr_lower: | ||
| 62 | if current_letter not in diff_letters: | 52 | if current_letter not in diff_letters: | ||
| 63 | diff_letters.append(current_letter) | 53 | diff_letters.append(current_letter) | ||
| 64 | 54 | ||||
| 65 | return len(diff_letters) | 55 | return len(diff_letters) | ||
| 66 | 56 | ||||
| 67 | def is_too_expensive(price): | 57 | def is_too_expensive(price): | ||
| n | 68 | if price>42.00: | n | 58 | return price > 42 |
| 69 | return True | ||||
| 70 | return False | ||||
| 71 | 59 | ||||
| 72 | def is_shrub(name): | 60 | def is_shrub(name): | ||
| n | 73 | name_lower = str(name).lower() | n | 61 | name_lower = name.lower() |
| 74 | if name_lower == "shrub" or name_lower == "bush" or name_lower == "храст": | 62 | return name_lower in ("shrub", "храст", "bush") | ||
| 75 | return True | ||||
| 76 | return False | ||||
| 77 | 63 | ||||
| 78 | def isDict(argument): | 64 | def isDict(argument): | ||
| 79 | return type(argument) == dict | 65 | return type(argument) == dict | ||
| 80 | 66 | ||||
| t | t | 67 | print(function_that_says_ni({"name": "храст", "cost": 1})) |
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||