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

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

10 точки общо

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

 1def function_that_says_ni(*args, **kwargs):
 2
 3    sum_of_costs = 0
 4    bushes = ("храст", "bush", "shrub")
 5    all_names = ""
 6
 7    for arg in args:
 8        if type(arg) is dict and "name" in arg:
 9            if arg["name"].lower() in bushes:
10                sum_of_costs += arg.get("cost", 0)
11    
12    for arg in kwargs:
13        if type(kwargs[arg]) is dict:
14            value = kwargs[arg]
15            if "name" in value and value["name"].lower() in bushes:
16                sum_of_costs += value.get("cost", 0)
17                all_names += arg 
18
19    integer_cost = int(sum_of_costs)
20    number_of_unique_characters = len(set(all_names))
21
22    if integer_cost == 0:
23        return "Ni!"
24    if sum_of_costs > 42:
25        return "Ni!"    
26    if number_of_unique_characters % (int(sum_of_costs)) != 0:
27        return "Ni!"
28
29    return f"{sum_of_costs:.2f}лв"

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

OK

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

f1def function_that_says_ni(*args, **kwargs):f1def function_that_says_ni(*args, **kwargs):
22
3    sum_of_costs = 03    sum_of_costs = 0
4    bushes = ("храст", "bush", "shrub")4    bushes = ("храст", "bush", "shrub")
5    all_names = ""5    all_names = ""
66
7    for arg in args:7    for arg in args:
8        if type(arg) is dict and "name" in arg:8        if type(arg) is dict and "name" in arg:
9            if arg["name"].lower() in bushes:9            if arg["name"].lower() in bushes:
n10                 sum_of_costs = sum_of_costs + arg.get("cost", 0)n10                sum_of_costs += arg.get("cost", 0)
11            else:
12                continue
13        else:
14            continue    
15    11    
16    for arg in kwargs:12    for arg in kwargs:
17        if type(kwargs[arg]) is dict:13        if type(kwargs[arg]) is dict:
18            value = kwargs[arg]14            value = kwargs[arg]
19            if "name" in value and value["name"].lower() in bushes:15            if "name" in value and value["name"].lower() in bushes:
n20                sum_of_costs = sum_of_costs + value.get("cost", 0)n16                sum_of_costs += value.get("cost", 0)
21                all_names = all_names + arg17                all_names += arg 
22            else:
23                continue
24        else:
25            continue    
2618
27    integer_cost = int(sum_of_costs)19    integer_cost = int(sum_of_costs)
28    number_of_unique_characters = len(set(all_names))20    number_of_unique_characters = len(set(all_names))
2921
n30    if integer_cost is 0:n22    if integer_cost == 0:
31        return "Ni!"23        return "Ni!"
32    if sum_of_costs > 42:24    if sum_of_costs > 42:
33        return "Ni!"    25        return "Ni!"    
t34    if number_of_unique_characters % (int(sum_of_costs)) is not 0:t26    if number_of_unique_characters % (int(sum_of_costs)) != 0:
35        return "Ni!"27        return "Ni!"
3628
37    return f"{sum_of_costs:.2f}лв"29    return f"{sum_of_costs:.2f}лв"
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op