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

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

10 точки общо

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

 1def function_that_says_ni(*args, **kwargs):
 2    valid_shrubs = []
 3    shrubbery_price = 0.0
 4    shrubbery_types = ('храст', 'shrub', 'bush')
 5    unique_symbols = set()
 6    highest_price = 42.00
 7
 8    for arg in args:
 9        if type(arg) is dict:
10            if 'name' in arg:
11                if arg['name'].lower() in shrubbery_types:
12                    valid_shrubs.append(arg)
13
14    for key, value in kwargs.items():
15        if type(value) is dict:
16            if 'name' in value:
17                if value['name'].lower() in shrubbery_types:
18                    valid_shrubs.append(value)
19                    unique_symbols.update(key)
20
21    for shrub in valid_shrubs:
22        if 'cost' in shrub:
23            shrubbery_price += shrub['cost']
24
25    if int(shrubbery_price) == 0:
26        return 'Ni!'
27
28    good_price = shrubbery_price <= highest_price
29    good_looking = (len(unique_symbols) % int(shrubbery_price) == 0)
30
31    if good_price and good_looking:
32        price_str = f'{shrubbery_price:.2f}лв'
33        return price_str
34
35    return 'Ni!'

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

OK

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

f1def function_that_says_ni(*args, **kwargs):f1def function_that_says_ni(*args, **kwargs):
2    valid_shrubs = []2    valid_shrubs = []
3    shrubbery_price = 0.03    shrubbery_price = 0.0
4    shrubbery_types = ('храст', 'shrub', 'bush')4    shrubbery_types = ('храст', 'shrub', 'bush')
5    unique_symbols = set()5    unique_symbols = set()
6    highest_price = 42.006    highest_price = 42.00
77
8    for arg in args:8    for arg in args:
9        if type(arg) is dict:9        if type(arg) is dict:
10            if 'name' in arg:10            if 'name' in arg:
11                if arg['name'].lower() in shrubbery_types:11                if arg['name'].lower() in shrubbery_types:
12                    valid_shrubs.append(arg)12                    valid_shrubs.append(arg)
1313
14    for key, value in kwargs.items():14    for key, value in kwargs.items():
15        if type(value) is dict:15        if type(value) is dict:
16            if 'name' in value:16            if 'name' in value:
t17                if value['name'].lower() == 'храст' or value['name'].lower() == 'shrub' or value['name'].lower() == 'bush':t17                if value['name'].lower() in shrubbery_types:
18                    valid_shrubs.append(value)18                    valid_shrubs.append(value)
19                    unique_symbols.update(key)19                    unique_symbols.update(key)
2020
21    for shrub in valid_shrubs:21    for shrub in valid_shrubs:
22        if 'cost' in shrub:22        if 'cost' in shrub:
23            shrubbery_price += shrub['cost']23            shrubbery_price += shrub['cost']
2424
25    if int(shrubbery_price) == 0:25    if int(shrubbery_price) == 0:
26        return 'Ni!'26        return 'Ni!'
2727
28    good_price = shrubbery_price <= highest_price28    good_price = shrubbery_price <= highest_price
29    good_looking = (len(unique_symbols) % int(shrubbery_price) == 0)29    good_looking = (len(unique_symbols) % int(shrubbery_price) == 0)
3030
31    if good_price and good_looking:31    if good_price and good_looking:
32        price_str = f'{shrubbery_price:.2f}лв'32        price_str = f'{shrubbery_price:.2f}лв'
33        return price_str33        return price_str
3434
35    return 'Ni!'35    return 'Ni!'
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    valid_shrubs = []2    valid_shrubs = []
3    shrubbery_price = 0.03    shrubbery_price = 0.0
nn4    shrubbery_types = ('храст', 'shrub', 'bush')
4    unique_symbols = set()5    unique_symbols = set()
5    highest_price = 42.006    highest_price = 42.00
n6    good_price = Falsen
7    good_looking = False
87
9    for arg in args:8    for arg in args:
10        if type(arg) is dict:9        if type(arg) is dict:
n11            if 'name' in arg.keys():n10            if 'name' in arg:
12                if arg['name'].lower() == 'храст' or arg['name'].lower() == 'shrub' or arg['name'].lower() == 'bush':11                if arg['name'].lower() in shrubbery_types:
13                    valid_shrubs.append(arg)12                    valid_shrubs.append(arg)
1413
15    for key, value in kwargs.items():14    for key, value in kwargs.items():
16        if type(value) is dict:15        if type(value) is dict:
n17            if 'name' in value.keys():n16            if 'name' in value:
18                if value['name'].lower() == 'храст' or value['name'].lower() == 'shrub' or value['name'].lower() == 'bush':17                if value['name'].lower() == 'храст' or value['name'].lower() == 'shrub' or value['name'].lower() == 'bush':
19                    valid_shrubs.append(value)18                    valid_shrubs.append(value)
n20                    for curr_symbol in range(len(key)):n
21                        unique_symbols.add(key[curr_symbol])19                    unique_symbols.update(key)
2220
23    for shrub in valid_shrubs:21    for shrub in valid_shrubs:
n24        if 'cost' in shrub.keys():n22        if 'cost' in shrub:
25            shrubbery_price += shrub['cost']23            shrubbery_price += shrub['cost']
2624
27    if int(shrubbery_price) == 0:25    if int(shrubbery_price) == 0:
28        return 'Ni!'26        return 'Ni!'
2927
n30    if shrubbery_price <= highest_price:n28    good_price = shrubbery_price <= highest_price
31        good_price = True
32 
33    ilen(unique_symbols) % int(shrubbery_price) == 0:29    good_looking = (len(unique_symbols) % int(shrubbery_price) == 0)
34        good_looking = True
3530
36    if good_price and good_looking:31    if good_price and good_looking:
37        price_str = f'{shrubbery_price:.2f}лв'32        price_str = f'{shrubbery_price:.2f}лв'
38        return price_str33        return price_str
3934
40    return 'Ni!'35    return 'Ni!'
t41 t
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op