1def is_shrub(potencial):
2 if type(potencial) is dict and "name" in potencial:
3 if potencial["name"].lower() in ("храст", "shrub", "bush"):
4 return True
5 return False
6
7def count_unique(my_dict):
8 all = str()
9 for key in my_dict:
10 all += key
11 unique = set(all)
12 return len(unique)
13
14def get_price(all_shrubs):
15 price = 0
16 for shrub in all_shrubs:
17 price += shrub.get('cost', 0)
18 return price
19
20def is_one_that_looks_nice(letters, price):
21 if int(price) == 0:
22 return False
23 if letters % int(price) == 0:
24 return True
25 else:
26 return False
27
28def function_that_says_ni(*args, **kwargs):
29 positional_shrubs = [shrub for shrub in args if is_shrub(shrub)]
30 named_shrubs = {key: value for key, value in kwargs.items() if is_shrub(value)}
31 unique_letters = count_unique(named_shrubs)
32 all_shrubs = positional_shrubs + list(named_shrubs.values())
33 price = get_price(all_shrubs)
34 if price <= 42.00 and is_one_that_looks_nice(unique_letters, price):
35 return f"{price:.2f}лв"
36 return "Ni!"
..........
----------------------------------------------------------------------
Ran 10 tests in 0.000s
OK
f | 1 | def is_shrub(potencial): | f | 1 | def is_shrub(potencial): |
2 | if type(potencial) is dict and "name" in potencial: | 2 | if type(potencial) is dict and "name" in potencial: | ||
3 | if potencial["name"].lower() in ("храст", "shrub", "bush"): | 3 | if potencial["name"].lower() in ("храст", "shrub", "bush"): | ||
4 | return True | 4 | return True | ||
5 | return False | 5 | return False | ||
6 | 6 | ||||
7 | def count_unique(my_dict): | 7 | def count_unique(my_dict): | ||
8 | all = str() | 8 | all = str() | ||
9 | for key in my_dict: | 9 | for key in my_dict: | ||
10 | all += key | 10 | all += key | ||
11 | unique = set(all) | 11 | unique = set(all) | ||
12 | return len(unique) | 12 | return len(unique) | ||
13 | 13 | ||||
14 | def get_price(all_shrubs): | 14 | def get_price(all_shrubs): | ||
15 | price = 0 | 15 | price = 0 | ||
16 | for shrub in all_shrubs: | 16 | for shrub in all_shrubs: | ||
n | 17 | if "cost" in shrub: | n | 17 | price += shrub.get('cost', 0) |
18 | price += shrub["cost"] | ||||
19 | return price | 18 | return price | ||
20 | 19 | ||||
21 | def is_one_that_looks_nice(letters, price): | 20 | def is_one_that_looks_nice(letters, price): | ||
n | 22 | if price // 1 == 0: | n | 21 | if int(price) == 0: |
23 | return False | 22 | return False | ||
n | 24 | if letters % (price // 1) == 0: | n | 23 | if letters % int(price) == 0: |
25 | return True | 24 | return True | ||
26 | else: | 25 | else: | ||
27 | return False | 26 | return False | ||
28 | 27 | ||||
29 | def function_that_says_ni(*args, **kwargs): | 28 | def function_that_says_ni(*args, **kwargs): | ||
30 | positional_shrubs = [shrub for shrub in args if is_shrub(shrub)] | 29 | positional_shrubs = [shrub for shrub in args if is_shrub(shrub)] | ||
31 | named_shrubs = {key: value for key, value in kwargs.items() if is_shrub(value)} | 30 | named_shrubs = {key: value for key, value in kwargs.items() if is_shrub(value)} | ||
32 | unique_letters = count_unique(named_shrubs) | 31 | unique_letters = count_unique(named_shrubs) | ||
33 | all_shrubs = positional_shrubs + list(named_shrubs.values()) | 32 | all_shrubs = positional_shrubs + list(named_shrubs.values()) | ||
34 | price = get_price(all_shrubs) | 33 | price = get_price(all_shrubs) | ||
35 | if price <= 42.00 and is_one_that_looks_nice(unique_letters, price): | 34 | if price <= 42.00 and is_one_that_looks_nice(unique_letters, price): | ||
36 | return f"{price:.2f}лв" | 35 | return f"{price:.2f}лв" | ||
t | 37 | else: | t | ||
38 | return "Ni!" | 36 | return "Ni!" |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
n | 1 | def is_hrast(potencial): | n | 1 | def is_shrub(potencial): |
2 | if type(potencial) == dict and "name" in potencial: | 2 | if type(potencial) is dict and "name" in potencial: | ||
3 | if potencial["name"].lower() == "храст" or potencial["name"].lower() == "shrub" or potencial["name"].lower() == "bush": | 3 | if potencial["name"].lower() in ("храст", "shrub", "bush"): | ||
4 | return True | 4 | return True | ||
5 | return False | 5 | return False | ||
6 | 6 | ||||
7 | def count_unique(my_dict): | 7 | def count_unique(my_dict): | ||
8 | all = str() | 8 | all = str() | ||
9 | for key in my_dict: | 9 | for key in my_dict: | ||
10 | all += key | 10 | all += key | ||
11 | unique = set(all) | 11 | unique = set(all) | ||
12 | return len(unique) | 12 | return len(unique) | ||
13 | 13 | ||||
n | 14 | def get_price(hrastalak): | n | 14 | def get_price(all_shrubs): |
15 | price = 0 | 15 | price = 0 | ||
n | 16 | for hrast in hrastalak: | n | 16 | for shrub in all_shrubs: |
17 | if "cost" in hrast: | 17 | if "cost" in shrub: | ||
18 | price += hrast["cost"] | 18 | price += shrub["cost"] | ||
19 | return price | 19 | return price | ||
20 | 20 | ||||
21 | def is_one_that_looks_nice(letters, price): | 21 | def is_one_that_looks_nice(letters, price): | ||
22 | if price // 1 == 0: | 22 | if price // 1 == 0: | ||
23 | return False | 23 | return False | ||
24 | if letters % (price // 1) == 0: | 24 | if letters % (price // 1) == 0: | ||
25 | return True | 25 | return True | ||
26 | else: | 26 | else: | ||
27 | return False | 27 | return False | ||
28 | 28 | ||||
29 | def function_that_says_ni(*args, **kwargs): | 29 | def function_that_says_ni(*args, **kwargs): | ||
t | 30 | positional_hrasti = [hrast for hrast in args if is_hrast(hrast)] | t | 30 | positional_shrubs = [shrub for shrub in args if is_shrub(shrub)] |
31 | named_hrasti = {key: value for key, value in kwargs.items() if is_hrast(value)} | 31 | named_shrubs = {key: value for key, value in kwargs.items() if is_shrub(value)} | ||
32 | unique_letters = count_unique(named_hrasti) | 32 | unique_letters = count_unique(named_shrubs) | ||
33 | hrastalak = positional_hrasti + list(named_hrasti.values()) | 33 | all_shrubs = positional_shrubs + list(named_shrubs.values()) | ||
34 | price = get_price(hrastalak) | 34 | price = get_price(all_shrubs) | ||
35 | if price <= 42.00 and is_one_that_looks_nice(unique_letters, price): | 35 | if price <= 42.00 and is_one_that_looks_nice(unique_letters, price): | ||
36 | return f"{price:.2f}лв" | 36 | return f"{price:.2f}лв" | ||
37 | else: | 37 | else: | ||
38 | return "Ni!" | 38 | return "Ni!" |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | def is_hrast(potencial): | f | 1 | def is_hrast(potencial): |
n | 2 | if (type(potencial) == dict and "name" in potencial): | n | 2 | if type(potencial) == dict and "name" in potencial: |
3 | if(potencial["name"].lower() == "храст" or potencial["name"].lower() == "shrub" or potencial["name"].lower() == "bush"): | 3 | if potencial["name"].lower() == "храст" or potencial["name"].lower() == "shrub" or potencial["name"].lower() == "bush": | ||
4 | return True | 4 | return True | ||
5 | return False | 5 | return False | ||
6 | 6 | ||||
7 | def count_unique(my_dict): | 7 | def count_unique(my_dict): | ||
8 | all = str() | 8 | all = str() | ||
9 | for key in my_dict: | 9 | for key in my_dict: | ||
10 | all += key | 10 | all += key | ||
11 | unique = set(all) | 11 | unique = set(all) | ||
12 | return len(unique) | 12 | return len(unique) | ||
13 | 13 | ||||
14 | def get_price(hrastalak): | 14 | def get_price(hrastalak): | ||
15 | price = 0 | 15 | price = 0 | ||
16 | for hrast in hrastalak: | 16 | for hrast in hrastalak: | ||
t | 17 | if ("cost" in hrast): | t | 17 | if "cost" in hrast: |
18 | price += hrast["cost"] | 18 | price += hrast["cost"] | ||
19 | return price | 19 | return price | ||
20 | 20 | ||||
21 | def is_one_that_looks_nice(letters, price): | 21 | def is_one_that_looks_nice(letters, price): | ||
22 | if price // 1 == 0: | 22 | if price // 1 == 0: | ||
23 | return False | 23 | return False | ||
24 | if letters % (price // 1) == 0: | 24 | if letters % (price // 1) == 0: | ||
25 | return True | 25 | return True | ||
26 | else: | 26 | else: | ||
27 | return False | 27 | return False | ||
28 | 28 | ||||
29 | def function_that_says_ni(*args, **kwargs): | 29 | def function_that_says_ni(*args, **kwargs): | ||
30 | positional_hrasti = [hrast for hrast in args if is_hrast(hrast)] | 30 | positional_hrasti = [hrast for hrast in args if is_hrast(hrast)] | ||
31 | named_hrasti = {key: value for key, value in kwargs.items() if is_hrast(value)} | 31 | named_hrasti = {key: value for key, value in kwargs.items() if is_hrast(value)} | ||
32 | unique_letters = count_unique(named_hrasti) | 32 | unique_letters = count_unique(named_hrasti) | ||
33 | hrastalak = positional_hrasti + list(named_hrasti.values()) | 33 | hrastalak = positional_hrasti + list(named_hrasti.values()) | ||
34 | price = get_price(hrastalak) | 34 | price = get_price(hrastalak) | ||
35 | if price <= 42.00 and is_one_that_looks_nice(unique_letters, price): | 35 | if price <= 42.00 and is_one_that_looks_nice(unique_letters, price): | ||
36 | return f"{price:.2f}лв" | 36 | return f"{price:.2f}лв" | ||
37 | else: | 37 | else: | ||
38 | return "Ni!" | 38 | return "Ni!" |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|