Домашни > Функцията, която казва "Ni!" > Решения > Решението на Марина Господинова

Резултати
10 точки от тестове
0 точки от учител

10 точки общо

10 успешни теста
0 неуспешни теста
Код

 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

Дискусия
История

f1def is_shrub(potencial):f1def 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 True4                 return True
5    return False            5    return False            
66
7def count_unique(my_dict):7def count_unique(my_dict):
8     all = str()8     all = str()
9     for key in my_dict:9     for key in my_dict:
10        all += key10        all += key
11     unique = set(all)11     unique = set(all)
12     return len(unique)12     return len(unique)
13          13          
14def get_price(all_shrubs):14def get_price(all_shrubs):
15     price = 015     price = 0
16     for shrub in all_shrubs:16     for shrub in all_shrubs:
n17          if "cost" in shrub:n17          price += shrub.get('cost', 0)
18               price += shrub["cost"]
19     return price          18     return price          
2019
21def is_one_that_looks_nice(letters, price):20def is_one_that_looks_nice(letters, price):
n22     if price // 1 == 0:n21     if int(price) == 0:
23        return False22        return False
n24     if letters % (price // 1) == 0:n23     if letters % int(price) == 0:
25        return True24        return True
26     else:25     else:
27        return False26        return False
2827
29def function_that_says_ni(*args, **kwargs):28def 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}лв"
t37    else:t
38        return "Ni!"36    return "Ni!"
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

n1def is_hrast(potencial):n1def 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 True4                 return True
5    return False            5    return False            
66
7def count_unique(my_dict):7def count_unique(my_dict):
8     all = str()8     all = str()
9     for key in my_dict:9     for key in my_dict:
10        all += key10        all += key
11     unique = set(all)11     unique = set(all)
12     return len(unique)12     return len(unique)
13          13          
n14def get_price(hrastalak):n14def get_price(all_shrubs):
15     price = 015     price = 0
n16     for hrast in hrastalak:n16     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          
2020
21def is_one_that_looks_nice(letters, price):21def is_one_that_looks_nice(letters, price):
22     if price // 1 == 0:22     if price // 1 == 0:
23        return False23        return False
24     if letters % (price // 1) == 0:24     if letters % (price // 1) == 0:
25        return True25        return True
26     else:26     else:
27        return False27        return False
2828
29def function_that_says_ni(*args, **kwargs):29def function_that_says_ni(*args, **kwargs):
t30    positional_hrasti = [hrast for hrast in args if is_hrast(hrast)]t30    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
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

f1def is_hrast(potencial):f1def is_hrast(potencial):
n2    if (type(potencial) == dict and "name" in potencial):n2    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 True4                 return True
5    return False            5    return False            
66
7def count_unique(my_dict):7def count_unique(my_dict):
8     all = str()8     all = str()
9     for key in my_dict:9     for key in my_dict:
10        all += key10        all += key
11     unique = set(all)11     unique = set(all)
12     return len(unique)12     return len(unique)
13          13          
14def get_price(hrastalak):14def get_price(hrastalak):
15     price = 015     price = 0
16     for hrast in hrastalak:16     for hrast in hrastalak:
t17          if ("cost" in hrast):t17          if "cost" in hrast:
18               price += hrast["cost"]18               price += hrast["cost"]
19     return price          19     return price          
2020
21def is_one_that_looks_nice(letters, price):21def is_one_that_looks_nice(letters, price):
22     if price // 1 == 0:22     if price // 1 == 0:
23        return False23        return False
24     if letters % (price // 1) == 0:24     if letters % (price // 1) == 0:
25        return True25        return True
26     else:26     else:
27        return False27        return False
2828
29def function_that_says_ni(*args, **kwargs):29def 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
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op