f | def function_that_says_ni(*args, **kwargs): | f | def function_that_says_ni(*args, **kwargs): |
| total_cost = 0 | | total_cost = 0 |
| accepted_bushes_count = 0 | | accepted_bushes_count = 0 |
| | | |
| for argument in args: | | for argument in args: |
n | if type(argument) == dict and is_bush_valid(argument): | n | if type(argument) is dict and is_bush_valid(argument): |
| total_cost += argument.get("cost", 0) | | total_cost += argument.get("cost", 0) |
| accepted_bushes_count += 1 | | accepted_bushes_count += 1 |
| | | |
| accepted_bushes_keys = [] | | accepted_bushes_keys = [] |
| | | |
| for key, value in kwargs.items(): | | for key, value in kwargs.items(): |
n | if type(value) == dict and is_bush_valid(value): | n | if type(value) is dict and is_bush_valid(value): |
| total_cost += value.get("cost", 0) | | total_cost += value.get("cost", 0) |
| accepted_bushes_count += 1 | | accepted_bushes_count += 1 |
| accepted_bushes_keys.append(key) | | accepted_bushes_keys.append(key) |
| | | |
n | if ( | n | |
| accepted_bushes_count != 0 and | | if (accepted_bushes_count != 0 and |
| is_shrubbery_nice(total_cost, accepted_bushes_keys) and | | is_shrubbery_nice(total_cost, accepted_bushes_keys) and not |
| not is_sum_expensive(total_cost) | | total_cost > 42 |
| ): | | ): |
| return f"{total_cost:.2f}лв" | | return f"{total_cost:.2f}лв" |
| else: | | else: |
| return "Ni!" | | return "Ni!" |
| | | |
| | | |
n | def is_sum_expensive(total): | n | |
| return total > 42 | | |
| | | |
| | | |
| def get_unique_symbols_count(keys): | | def get_unique_symbols_count(keys): |
n | keys_str = ''.join(keys) | n | |
| return len(set(keys_str)) | | return len(set(''.join(keys))) |
| | | |
| | | |
| def is_bush_valid(bush): | | def is_bush_valid(bush): |
| return ("name" in bush and | | return ("name" in bush and |
t | type(bush["name"]) == str and | t | type(bush["name"]) is str and |
| bush["name"].lower() in {"храст", "shrub", "bush"}) | | bush["name"].lower() in {"храст", "shrub", "bush"}) |
| | | |
| | | |
| def is_shrubbery_nice(total, accepted_keys): | | def is_shrubbery_nice(total, accepted_keys): |
| whole_part = int(total) | | whole_part = int(total) |
| return (whole_part != 0 and | | return (whole_part != 0 and |
| get_unique_symbols_count(accepted_keys) % whole_part == 0) | | get_unique_symbols_count(accepted_keys) % whole_part == 0) |