t | def is_bush(potential_bush): | t | def is_bush(potential_bush): |
| valid_names = {"храст", "shrub", "bush"} | | valid_names = {"храст", "shrub", "bush"} |
| | | |
| if "name" in potential_bush and type(potential_bush["name"]) == str: | | if "name" in potential_bush and type(potential_bush["name"]) == str: |
| name_lower = potential_bush["name"].lower() | | name_lower = potential_bush["name"].lower() |
| return name_lower in valid_names | | return name_lower in valid_names |
| else: | | else: |
| return False | | return False |
| | | |
| def function_that_says_ni(*args, **kwargs): | | def function_that_says_ni(*args, **kwargs): |
| | | |
| merged = list(args) + list(kwargs.values()) | | merged = list(args) + list(kwargs.values()) |
| total_cost = 0 | | total_cost = 0 |
| | | |
| for element in merged : | | for element in merged : |
| if type(element) == dict and is_bush(element): | | if type(element) == dict and is_bush(element): |
| current_cost = element.get("cost", 0) | | current_cost = element.get("cost", 0) |
| if type(current_cost) == int or type(current_cost) == float: | | if type(current_cost) == int or type(current_cost) == float: |
| total_cost += current_cost | | total_cost += current_cost |
| | | |
| unique_letters = set() | | unique_letters = set() |
| for key, value in kwargs.items(): | | for key, value in kwargs.items(): |
| if type(value) == dict and is_bush(value): | | if type(value) == dict and is_bush(value): |
| unique_letters.update(key) | | unique_letters.update(key) |
| if '_' in key: | | if '_' in key: |
| unique_letters.add('_') | | unique_letters.add('_') |
| | | |
| num_unique_letters = len(unique_letters) | | num_unique_letters = len(unique_letters) |
| | | |
| | | |
| if (int(total_cost) == 0): | | if (int(total_cost) == 0): |
| one_that_looks_nice = False | | one_that_looks_nice = False |
| else: | | else: |
| one_that_looks_nice = num_unique_letters % int(total_cost) == 0 | | one_that_looks_nice = num_unique_letters % int(total_cost) == 0 |
| | | |
| | | |
| if total_cost <= 42 and one_that_looks_nice: | | if total_cost <= 42 and one_that_looks_nice: |
| return f"{total_cost:.2f}лв" | | return f"{total_cost:.2f}лв" |
| else: | | else: |
| return "Ni!" | | return "Ni!" |
| | | |
| #print(function_that_says_ni({"name": "храст", "cost": 120})) | | #print(function_that_says_ni({"name": "храст", "cost": 120})) |
| #print(function_that_says_ni({"name": "храст", "cost": 1})) | | #print(function_that_says_ni({"name": "храст", "cost": 1})) |
| #print(function_that_says_ni(aabcc={"name": "bush", "cost": 3.20})) | | #print(function_that_says_ni(aabcc={"name": "bush", "cost": 3.20})) |
| #print(function_that_says_ni({"name": "чегарак", "cost": 1.00})) | | #print(function_that_says_ni({"name": "чегарак", "cost": 1.00})) |
| #print(function_that_says_ni({"name": "храст", "cost": 2.00})) | | #print(function_that_says_ni({"name": "храст", "cost": 2.00})) |
| #print(function_that_says_ni({"name": "shrub", "cost": 3.00})) | | #print(function_that_says_ni({"name": "shrub", "cost": 3.00})) |
| #print(function_that_says_ni({"name": "bush"})) | | #print(function_that_says_ni({"name": "bush"})) |
22.10.2024 11:12
22.10.2024 11:09
22.10.2024 11:10
22.10.2024 11:09
22.10.2024 11:10
22.10.2024 11:11
22.10.2024 11:11