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

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

10 точки общо

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

 1def function_that_says_ni(*args, **kwargs):
 2    cost = 0
 3    letters = set()
 4    nice_trees = ("храст", "shrub", "bush")
 5    for arg in args:
 6        if type(arg) is dict:
 7            if "name" in arg:
 8                if arg["name"].lower() in nice_trees:
 9                    if "cost" in arg:
10                        cost += arg["cost"]
11
12    for arg in kwargs:
13        if type(kwargs[arg]) is dict:
14            if "name" in kwargs[arg]:
15                if kwargs[arg]["name"].lower() in nice_trees:
16                    for letter in arg:
17                        if letter.isalpha() or letter == '_':
18                            letters.add(letter)
19                    if "cost" in kwargs[arg]:
20                        cost += kwargs[arg]["cost"] 
21
22    if cost > 42 or int(cost) == 0:
23        return "Ni!"
24    if len(letters) % int(cost) == 0:
25        return f"{format(cost,'.2f')}лв"
26    return "Ni!"
27        

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

OK

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

f1def function_that_says_ni(*args, **kwargs):f1def function_that_says_ni(*args, **kwargs):
n2    cost = 0.0n2    cost = 0
3    letters=set()3    letters = set()
4    nice_trees = ("храст", "shrub", "bush")
4    for arg in args:5    for arg in args:
5        if type(arg) is dict:6        if type(arg) is dict:
6            if "name" in arg:7            if "name" in arg:
n7                if arg["name"].lower() in ("храст", "shrub", "bush"):n8                if arg["name"].lower() in nice_trees:
8                    if "cost" in arg:9                    if "cost" in arg:
9                        cost += arg["cost"]10                        cost += arg["cost"]
n10                        n11 
11    for arg in kwargs:12    for arg in kwargs:
12        if type(kwargs[arg]) is dict:13        if type(kwargs[arg]) is dict:
13            if "name" in kwargs[arg]:14            if "name" in kwargs[arg]:
n14                if kwargs[arg]["name"].lower() in ("храст", "shrub", "bush"):n15                if kwargs[arg]["name"].lower() in nice_trees:
15                    for letter in arg:16                    for letter in arg:
16                        if letter.isalpha() or letter == '_':17                        if letter.isalpha() or letter == '_':
17                            letters.add(letter)18                            letters.add(letter)
18                    if "cost" in kwargs[arg]:19                    if "cost" in kwargs[arg]:
19                        cost += kwargs[arg]["cost"] 20                        cost += kwargs[arg]["cost"] 
2021
21    if cost > 42 or int(cost) == 0:22    if cost > 42 or int(cost) == 0:
t22        return("Ni!")t23        return "Ni!"
23    else:
24        if len(letters) % int(cost) == 0:24    if len(letters) % int(cost) == 0:
25            return(f"{format(cost,'.2f')}лв")25        return f"{format(cost,'.2f')}лв"
26    return("Ni!")26    return "Ni!"
27        27        
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

f1def function_that_says_ni(*args, **kwargs):f1def function_that_says_ni(*args, **kwargs):
2    cost = 0.02    cost = 0.0
3    letters=set()3    letters=set()
nn4    for arg in args:
5        if type(arg) is dict:
6            if "name" in arg:
7                if arg["name"].lower() in ("храст", "shrub", "bush"):
8                    if "cost" in arg:
9                        cost += arg["cost"]
10                        
4    for arg in kwargs:11    for arg in kwargs:
5        if type(kwargs[arg]) is dict:12        if type(kwargs[arg]) is dict:
6            if "name" in kwargs[arg]:13            if "name" in kwargs[arg]:
7                if kwargs[arg]["name"].lower() in ("храст", "shrub", "bush"):14                if kwargs[arg]["name"].lower() in ("храст", "shrub", "bush"):
8                    for letter in arg:15                    for letter in arg:
9                        if letter.isalpha() or letter == '_':16                        if letter.isalpha() or letter == '_':
10                            letters.add(letter)17                            letters.add(letter)
11                    if "cost" in kwargs[arg]:18                    if "cost" in kwargs[arg]:
12                        cost += kwargs[arg]["cost"] 19                        cost += kwargs[arg]["cost"] 
1320
n14    for arg in args:n
15        if type(arg) is dict:
16            if "name" in arg:
17                if arg["name"].lower() in ("храст", "shrub", "bush"):
18                    if "cost" in arg:
19                        cost += arg["cost"]
20 
21    if cost > 42 or int(cost) == 0:21    if cost > 42 or int(cost) == 0:
22        return("Ni!")22        return("Ni!")
23    else:23    else:
24        if len(letters) % int(cost) == 0:24        if len(letters) % int(cost) == 0:
25            return(f"{format(cost,'.2f')}лв")25            return(f"{format(cost,'.2f')}лв")
26    return("Ni!")26    return("Ni!")
27        27        
t28print(function_that_says_ni({"name": "храсТ", "cost": 3.20}))t
29print(function_that_says_ni(4, a=5))
30print(function_that_says_ni())
31print(function_that_says_ni(ab={"name": "храст", "cost": 1.80}, bc={"name": "храст", "cost": 1}))
32print(function_that_says_ni(b={"name": "храст", "cost": 1.80}, bc={"name": "храс0т", "cost": 1}))
33print(function_that_says_ni({"name": "храст", "cost": 120}))
34print(function_that_says_ni({"name": "храст", "cost": 1}))
35print(function_that_says_ni(aabcc={"name": "bush", "cost": 3.20}))
36    
37print(function_that_says_ni({"ddd": "храст", "cost": 1.50}, {"namae": "sHRub", "cost": 3.00})) #ni
38print(function_that_says_ni({"name": "храст"}, {"name": "храст", "cost": 0.0}, ["ffffffffff", {1, 2, 3}]))#ni
39print(function_that_says_ni({"name": "храст"}, {"name": "bush", "cost": 33.33}))#33.33
40print(function_that_says_ni({"name": "храст"}, {"name": "buSh"}))#ni
41print(function_that_says_ni( {"name": "Храст", "cost": 11.0}, ad={"name": "дърво", "cost": 1.80}, c = "pypy"))#11.00
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op