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

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

10 точки общо

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

 1def function_that_says_ni(*args, **kwargs):
 2    shrubs = []
 3    valid_names = {"храст", "shrub", "bush"}
 4
 5    for item in args:
 6        if type(item) is dict and "name" in item:
 7            if item["name"].lower() in valid_names:
 8                shrubs.append(item)
 9
10    unique_letters = set()
11    for key, value in kwargs.items():
12        if type(value) is dict and "name" in value:
13            if value["name"].lower() in valid_names:
14                shrubs.append(value)
15                unique_letters.update(key)
16
17    total_sum = 0.0
18    for bush in shrubs:
19        total_sum += bush.get("cost", 0)
20
21    if total_sum > 42.00:
22        return "Ni!"
23
24    sum_in_int = int(total_sum)
25
26    if sum_in_int == 0 or (sum_in_int != 0 and len(unique_letters) % sum_in_int != 0):
27        return "Ni!"
28
29    return f"{total_sum:.2f}лв"

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

OK

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

f1def function_that_says_ni(*args, **kwargs):f1def function_that_says_ni(*args, **kwargs):
2    shrubs = []2    shrubs = []
3    valid_names = {"храст", "shrub", "bush"}3    valid_names = {"храст", "shrub", "bush"}
44
5    for item in args:5    for item in args:
6        if type(item) is dict and "name" in item:6        if type(item) is dict and "name" in item:
7            if item["name"].lower() in valid_names:7            if item["name"].lower() in valid_names:
8                shrubs.append(item)8                shrubs.append(item)
99
10    unique_letters = set()10    unique_letters = set()
11    for key, value in kwargs.items():11    for key, value in kwargs.items():
12        if type(value) is dict and "name" in value:12        if type(value) is dict and "name" in value:
13            if value["name"].lower() in valid_names:13            if value["name"].lower() in valid_names:
14                shrubs.append(value)14                shrubs.append(value)
15                unique_letters.update(key)15                unique_letters.update(key)
1616
17    total_sum = 0.017    total_sum = 0.0
18    for bush in shrubs:18    for bush in shrubs:
t19        total_sum += bush.get('cost', 0)t19        total_sum += bush.get("cost", 0)
2020
21    if total_sum > 42.00:21    if total_sum > 42.00:
22        return "Ni!"22        return "Ni!"
2323
24    sum_in_int = int(total_sum)24    sum_in_int = int(total_sum)
2525
26    if sum_in_int == 0 or (sum_in_int != 0 and len(unique_letters) % sum_in_int != 0):26    if sum_in_int == 0 or (sum_in_int != 0 and len(unique_letters) % sum_in_int != 0):
27        return "Ni!"27        return "Ni!"
2828
29    return f"{total_sum:.2f}лв"29    return f"{total_sum:.2f}лв"
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    shrubs = []2    shrubs = []
3    valid_names = {"храст", "shrub", "bush"}3    valid_names = {"храст", "shrub", "bush"}
44
5    for item in args:5    for item in args:
n6        if type(item) == type(dict()) and "name" in item:n6        if type(item) is dict and "name" in item:
7            if item["name"].lower() in valid_names:7            if item["name"].lower() in valid_names:
8                shrubs.append(item)8                shrubs.append(item)
99
10    unique_letters = set()10    unique_letters = set()
11    for key, value in kwargs.items():11    for key, value in kwargs.items():
n12        if type(value) == type(dict()) and "name" in value:n12        if type(value) is dict and "name" in value:
13            if value["name"].lower() in valid_names:13            if value["name"].lower() in valid_names:
14                shrubs.append(value)14                shrubs.append(value)
15                unique_letters.update(key)15                unique_letters.update(key)
1616
17    total_sum = 0.017    total_sum = 0.0
18    for bush in shrubs:18    for bush in shrubs:
t19        if "cost" in bush:t19        total_sum += bush.get('cost', 0)
20            total_sum += float(bush["cost"])
2120
22    if total_sum > 42.00:21    if total_sum > 42.00:
23        return "Ni!"22        return "Ni!"
2423
25    sum_in_int = int(total_sum)24    sum_in_int = int(total_sum)
2625
27    if sum_in_int == 0 or (sum_in_int != 0 and len(unique_letters) % sum_in_int != 0):26    if sum_in_int == 0 or (sum_in_int != 0 and len(unique_letters) % sum_in_int != 0):
28        return "Ni!"27        return "Ni!"
2928
30    return f"{total_sum:.2f}лв"29    return f"{total_sum:.2f}лв"
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    shrubs = []2    shrubs = []
3    valid_names = {"храст", "shrub", "bush"}3    valid_names = {"храст", "shrub", "bush"}
44
5    for item in args:5    for item in args:
6        if type(item) == type(dict()) and "name" in item:6        if type(item) == type(dict()) and "name" in item:
7            if item["name"].lower() in valid_names:7            if item["name"].lower() in valid_names:
8                shrubs.append(item)8                shrubs.append(item)
99
10    unique_letters = set()10    unique_letters = set()
11    for key, value in kwargs.items():11    for key, value in kwargs.items():
12        if type(value) == type(dict()) and "name" in value:12        if type(value) == type(dict()) and "name" in value:
13            if value["name"].lower() in valid_names:13            if value["name"].lower() in valid_names:
14                shrubs.append(value)14                shrubs.append(value)
15                unique_letters.update(key)15                unique_letters.update(key)
1616
17    total_sum = 0.017    total_sum = 0.0
18    for bush in shrubs:18    for bush in shrubs:
19        if "cost" in bush:19        if "cost" in bush:
20            total_sum += float(bush["cost"])20            total_sum += float(bush["cost"])
2121
22    if total_sum > 42.00:22    if total_sum > 42.00:
23        return "Ni!"23        return "Ni!"
2424
25    sum_in_int = int(total_sum)25    sum_in_int = int(total_sum)
2626
27    if sum_in_int == 0 or (sum_in_int != 0 and len(unique_letters) % sum_in_int != 0):27    if sum_in_int == 0 or (sum_in_int != 0 and len(unique_letters) % sum_in_int != 0):
28        return "Ni!"28        return "Ni!"
2929
t30    return f"{total_sum:.2f} лв."t30    return f"{total_sum:.2f}лв"
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op