1def function_that_says_ni(*args, **kwargs):
2 true_names_of_bush = ("храст", "bush", "shrub")
3 sum_of_costs_of_shrubbery = 0
4 distinct_symbols_in_names = set()
5 for positional_dict in args:
6 if type(positional_dict) is dict:
7 if positional_dict.get("name","").lower() in true_names_of_bush:
8 sum_of_costs_of_shrubbery +=positional_dict.get("cost", 0)
9 for name_of_dict, the_dict in kwargs.items():
10 if type(the_dict) is dict:
11 if the_dict.get("name","").lower() in true_names_of_bush:
12 sum_of_costs_of_shrubbery += the_dict.get("cost", 0)
13 for symbol in name_of_dict:
14 distinct_symbols_in_names.add(symbol)
15 integer_part_of_sum = int(sum_of_costs_of_shrubbery)
16 if sum_of_costs_of_shrubbery <= 42.0:
17 if integer_part_of_sum == 0:
18 return "Ni!"
19 else:
20 if len(distinct_symbols_in_names) % integer_part_of_sum == 0:
21 return "{:.2f}лв".format(sum_of_costs_of_shrubbery)
22 return "Ni!"
..........
----------------------------------------------------------------------
Ran 10 tests in 0.000s
OK
Виктор Бечев
19.10.2024 11:55**Генерална бележка** - обратната ни връзка рядко касае това колко добре ще работи решението или колко теста ще минат. От теб зависи колко си уверена да правиш промени по решението си, може в настоящото домашно да избереш просто да вземеш обратната връзка като такава и да я имплементираш следващия път. Просто с времето ще сме по-настоятелни по отношение на добрите практики, питонски идиоми и стил.
П.П. Що се отнася до стила - good job.
|
| f | 1 | def function_that_says_ni(*args, **kwargs): | f | 1 | def function_that_says_ni(*args, **kwargs): |
| n | n | 2 | true_names_of_bush = ("храст", "bush", "shrub") | ||
| 2 | sum_of_costs_of_shrubbery = 0 | 3 | sum_of_costs_of_shrubbery = 0 | ||
| 3 | distinct_symbols_in_names = set() | 4 | distinct_symbols_in_names = set() | ||
| 4 | for positional_dict in args: | 5 | for positional_dict in args: | ||
| n | 5 | positional_bush = 0 | n | ||
| 6 | if type(positional_dict) is dict: | 6 | if type(positional_dict) is dict: | ||
| n | 7 | for key, value in positional_dict.items(): | n | 7 | if positional_dict.get("name","").lower() in true_names_of_bush: |
| 8 | if key == "name": | 8 | sum_of_costs_of_shrubbery +=positional_dict.get("cost", 0) | ||
| 9 | if value.lower() == "храст" or value.lower() == "bush" or value.lower() == "shrub": | ||||
| 10 | positional_bush = 1 | ||||
| 11 | if key == "cost" and positional_bush == 1: | ||||
| 12 | sum_of_costs_of_shrubbery += value | ||||
| 13 | for name_of_dict, the_dict in kwargs.items(): | 9 | for name_of_dict, the_dict in kwargs.items(): | ||
| n | 14 | is_bush = 0 | n | ||
| 15 | if type(the_dict) is dict: | 10 | if type(the_dict) is dict: | ||
| t | 16 | for key, value in the_dict.items(): | t | 11 | if the_dict.get("name","").lower() in true_names_of_bush: |
| 17 | if key == "name": | ||||
| 18 | if value.lower() == "храст" or value.lower() == "bush" or value.lower() == "shrub": | ||||
| 19 | is_bush = 1 | ||||
| 20 | if key == "cost" and is_bush == 1: | ||||
| 21 | sum_of_costs_of_shrubbery += value | 12 | sum_of_costs_of_shrubbery += the_dict.get("cost", 0) | ||
| 22 | if is_bush == 1: | ||||
| 23 | for symbol in name_of_dict: | 13 | for symbol in name_of_dict: | ||
| 24 | distinct_symbols_in_names.add(symbol) | 14 | distinct_symbols_in_names.add(symbol) | ||
| 25 | integer_part_of_sum = int(sum_of_costs_of_shrubbery) | 15 | integer_part_of_sum = int(sum_of_costs_of_shrubbery) | ||
| 26 | if sum_of_costs_of_shrubbery <= 42.0: | 16 | if sum_of_costs_of_shrubbery <= 42.0: | ||
| 27 | if integer_part_of_sum == 0: | 17 | if integer_part_of_sum == 0: | ||
| 28 | return "Ni!" | 18 | return "Ni!" | ||
| 29 | else: | 19 | else: | ||
| 30 | if len(distinct_symbols_in_names) % integer_part_of_sum == 0: | 20 | if len(distinct_symbols_in_names) % integer_part_of_sum == 0: | ||
| 31 | return "{:.2f}лв".format(sum_of_costs_of_shrubbery) | 21 | return "{:.2f}лв".format(sum_of_costs_of_shrubbery) | ||
| 32 | return "Ni!" | 22 | return "Ni!" |
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||