f | VALID_SHRUBBERY_PARTS = ('храст', 'shrub', 'bush') | f | VALID_SHRUBBERY_PARTS = ('храст', 'shrub', 'bush') |
| MAX_PRICE = 42 | | MAX_PRICE = 42 |
| | | |
| | | |
| def function_that_says_ni(*args, **kwargs): | | def function_that_says_ni(*args, **kwargs): |
| price = 0 | | price = 0 |
| | | |
| price += check_args(args) # there are no keyword args in args so it returns only price | | price += check_args(args) # there are no keyword args in args so it returns only price |
| | | |
n | _ = check_kwargs(kwargs) | n | res = check_kwargs(kwargs) |
| price += _[0] | | price += res[0] |
| unique_letters = _[1] | | unique_letters = res[1] |
| | | |
| if int(price) > 0 and price <= MAX_PRICE and len(unique_letters) % int(price) == 0: | | if int(price) > 0 and price <= MAX_PRICE and len(unique_letters) % int(price) == 0: |
| return f'{price:.2f}лв' | | return f'{price:.2f}лв' |
| | | |
| return 'Ni!' | | return 'Ni!' |
| | | |
| def check_args(args): | | def check_args(args): |
| """Sums all relevant prices from args""" | | """Sums all relevant prices from args""" |
| price = 0 | | price = 0 |
| | | |
| for arg in args: | | for arg in args: |
| if type(arg) is dict: | | if type(arg) is dict: |
| if arg.get('name'): | | if arg.get('name'): |
| if arg['name'].lower() in VALID_SHRUBBERY_PARTS: | | if arg['name'].lower() in VALID_SHRUBBERY_PARTS: |
n | if arg.get('cost'): | n | price += arg.get('cost', 0) |
| price += arg['cost'] | | |
| | | |
| return price | | return price |
| | | |
| def check_kwargs(kwargs): | | def check_kwargs(kwargs): |
| """Sums all relevant prices from kwargs and gets all unique letters from names of named arguments""" | | """Sums all relevant prices from kwargs and gets all unique letters from names of named arguments""" |
| price = 0 | | price = 0 |
| unique_letters = set() | | unique_letters = set() |
| | | |
| for arg_name, item in kwargs.items(): | | for arg_name, item in kwargs.items(): |
| if type(item) is dict: | | if type(item) is dict: |
| if item.get('name'): | | if item.get('name'): |
| if item['name'].lower() in VALID_SHRUBBERY_PARTS: | | if item['name'].lower() in VALID_SHRUBBERY_PARTS: |
t | if item.get('cost'): | t | price += item.get('cost', 0) |
| price += item['cost'] | | |
| unique_letters.update(arg_name) | | unique_letters.update(arg_name) |
| | | |
| return price, unique_letters | | return price, unique_letters |