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

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

11 точки общо

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

 1def function_that_says_ni(*args, **kwargs):
 2
 3    price_of_shrubbery = 0
 4    unique_letter = set()
 5
 6    for shrub in args:
 7        if isinstance(shrub, dict) and "name" in shrub and shrub["name"].lower() in {"храст", "shrub", "bush"}:
 8            if "cost" in shrub and isinstance(shrub["cost"], (int, float)):
 9                price_of_shrubbery += shrub["cost"]
10                
11
12    for key, shrub in kwargs.items():
13        if isinstance(shrub, dict) and "name" in shrub and shrub["name"].lower() in {"храст", "shrub", "bush"}:
14            if "cost" in shrub and isinstance(shrub["cost"], (int, float)):
15                price_of_shrubbery += shrub["cost"]
16            unique_letter.update(key) 
17            
18    if price_of_shrubbery > 42.00:
19        return "Ni!"
20    
21    if int(price_of_shrubbery) == 0 or len(unique_letter) % int(price_of_shrubbery) != 0:
22        return "Ni!"
23    
24    return f"{price_of_shrubbery:.2f}лв" 

..........
----------------------------------------------------------------------
Ran 10 tests in 0.000s

OK

Дискусия
Георги Кунчев
21.10.2024 10:50

Добро решени. Имам само два вребни коментара, но като цяло е доста чисто и ясно.
История

f1def function_that_says_ni(*args, **kwargs):f1def function_that_says_ni(*args, **kwargs):
22
t3    price_of_shrubbery = 0.00t3    price_of_shrubbery = 0
4    unique_letter = set()4    unique_letter = set()
55
6    for shrub in args:6    for shrub in args:
7        if isinstance(shrub, dict) and "name" in shrub and shrub["name"].lower() in {"храст", "shrub", "bush"}:7        if isinstance(shrub, dict) and "name" in shrub and shrub["name"].lower() in {"храст", "shrub", "bush"}:
8            if "cost" in shrub and isinstance(shrub["cost"], (int, float)):8            if "cost" in shrub and isinstance(shrub["cost"], (int, float)):
9                price_of_shrubbery += shrub["cost"]9                price_of_shrubbery += shrub["cost"]
10                10                
1111
12    for key, shrub in kwargs.items():12    for key, shrub in kwargs.items():
13        if isinstance(shrub, dict) and "name" in shrub and shrub["name"].lower() in {"храст", "shrub", "bush"}:13        if isinstance(shrub, dict) and "name" in shrub and shrub["name"].lower() in {"храст", "shrub", "bush"}:
14            if "cost" in shrub and isinstance(shrub["cost"], (int, float)):14            if "cost" in shrub and isinstance(shrub["cost"], (int, float)):
15                price_of_shrubbery += shrub["cost"]15                price_of_shrubbery += shrub["cost"]
16            unique_letter.update(key) 16            unique_letter.update(key) 
17            17            
18    if price_of_shrubbery > 42.00:18    if price_of_shrubbery > 42.00:
19        return "Ni!"19        return "Ni!"
20    20    
21    if int(price_of_shrubbery) == 0 or len(unique_letter) % int(price_of_shrubbery) != 0:21    if int(price_of_shrubbery) == 0 or len(unique_letter) % int(price_of_shrubbery) != 0:
22        return "Ni!"22        return "Ni!"
23    23    
24    return f"{price_of_shrubbery:.2f}лв" 24    return f"{price_of_shrubbery:.2f}лв" 
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op