f | def is_a_bush(potential_bush, total_cost): | f | def is_a_bush(potential_bush, total_cost): |
n | | n | valid_names = ("храст", "bush", "shrub") |
| | | |
n | is_bush = False | n | |
| valid_names = ["храст", "bush", "shrub"] | | |
| | | |
| if( potential_bush.get('name')): | | |
| name = potential_bush.get('name').lower() | | name = potential_bush.get('name', '').lower() |
| | | |
n | # Checking if the name is valid | n | # Checking if the name is valid |
| for _name in valid_names: | | for curr_name in valid_names: |
| if(_name.lower() == name): | | if curr_name.lower() == name: |
| is_bush = True | | |
| cost = potential_bush.get('cost', 0) | | cost = potential_bush.get('cost', 0) |
| | | |
n | # Checking if the cost is valid - int or float | n | # Checking if the cost is valid - int or float |
| if isinstance(cost, (int, float)): | | if isinstance(cost, (int, float)): |
| total_cost += cost | | total_cost += cost |
| | | |
n | | n | return True, total_cost |
| | | |
| return is_bush, total_cost | | return False, total_cost |
| | | |
| def function_that_says_ni(*args, **kwargs): | | def function_that_says_ni(*args, **kwargs): |
n | | n | |
| total_cost = 0 | | total_cost = 0 |
n | is_bush = False | n | |
| unique_letters = set() | | unique_letters = set() |
| | | |
| # Looping through all args and searching for a bush | | # Looping through all args and searching for a bush |
| for arg in args: | | for arg in args: |
| if isinstance(arg, dict): | | if isinstance(arg, dict): |
n | is_bush, total_cost = is_a_bush(arg, total_cost) | n | _, total_cost = is_a_bush(arg, total_cost) |
| | | |
| # Looping through all kwargs and searching for a bush | | # Looping through all kwargs and searching for a bush |
| for var_name, kwarg in kwargs.items(): | | for var_name, kwarg in kwargs.items(): |
| if isinstance(kwarg, dict): | | if isinstance(kwarg, dict): |
| is_bush, total_cost = is_a_bush(kwarg, total_cost) | | is_bush, total_cost = is_a_bush(kwarg, total_cost) |
n | if(is_bush): | n | if is_bush: |
| unique_letters.update(set(var_name)) | | unique_letters.update(set(var_name)) |
| | | |
| unique_symbols_count = len(unique_letters) | | unique_symbols_count = len(unique_letters) |
| | | |
n | if(int(total_cost) != 0 and total_cost <= 42 and unique_symbols_count >= 0 | n | if (int(total_cost) != 0 and total_cost <= 42 and unique_symbols_count >= 0 |
| and unique_symbols_count % int(total_cost) == 0): | | and unique_symbols_count % int(total_cost) == 0): |
t | is_bush = True | t | |
| else: | | |
| is_bush = False | | |
| | | |
| if(is_bush): | | |
| return f"{total_cost:.2f}лв" | | return f"{total_cost:.2f}лв" |
| else: | | else: |
| return "Ni!" | | return "Ni!" |