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

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

9 точки общо

9 успешни теста
1 неуспешни теста
Код (Промененото решение след обратната връзка)

 1list_shrub = ["храст", "shrub", "bush"]
 2
 3def sum_positional_bush_price(*args):
 4    result = 0.00
 5    for item in args:
 6        if type(item) == dict and 'name' in item:
 7             if item['name'].lower() in list_shrub:
 8                result += item.get('cost', 0)
 9
10    return result
11
12
13def sum_naming_bush_price(unique_set, **kwargs):
14    result = 0.00
15    for name, bush in kwargs.items():
16        if type(bush) == dict and 'name' in bush:
17            if bush['name'].lower() in list_shrub:
18                for letter in name:
19                    unique_set.add(letter)
20                if 'cost' in bush:
21                    result += bush['cost']
22    return result
23
24
25def function_that_says_ni(*args, **kwargs):
26    price = 0.00
27    price += sum_positional_bush_price(*args)
28    
29    unique_set = set()
30    price += sum_naming_bush_price(unique_set, **kwargs)
31
32    price_in_int = int(price)
33    if 0 < price_in_int <= 42:
34        if len(unique_set) % price_in_int == 0:
35            return f"{price:.2f}лв"
36        
37    return "Ni!"

.....F....
======================================================================
FAIL: test_multiple_shrubs_sumс (test.TestNi.test_multiple_shrubs_sumс)
Test with a multiple shrubs and cornercase costs.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 38, in test_multiple_shrubs_sumс
self.assertEqual(function_that_says_ni({'name': 'shrub', 'cost': 20.01},
AssertionError: '42.01лв' != 'Ni!'
- 42.01лв
+ Ni!

----------------------------------------------------------------------
Ran 10 tests in 0.001s

FAILED (failures=1)

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

f1f1
2list_shrub = ["храст", "shrub", "bush"]2list_shrub = ["храст", "shrub", "bush"]
33
4def sum_positional_bush_price(*args):4def sum_positional_bush_price(*args):
n5    result = 0n5    result = 0.00
6    for item in args:6    for item in args:
7        if type(item) == dict and 'name' in item:7        if type(item) == dict and 'name' in item:
8             if item['name'].lower() in list_shrub:8             if item['name'].lower() in list_shrub:
9                result += item.get('cost', 0)9                result += item.get('cost', 0)
1010
11    return result11    return result
1212
1313
14def sum_naming_bush_price(unique_set, **kwargs):14def sum_naming_bush_price(unique_set, **kwargs):
t15    result = 0t15    result = 0.00
16    for name, bush in kwargs.items():16    for name, bush in kwargs.items():
17        if type(bush) == dict and 'name' in bush:17        if type(bush) == dict and 'name' in bush:
18            if bush['name'].lower() in list_shrub:18            if bush['name'].lower() in list_shrub:
19                for letter in name:19                for letter in name:
20                    unique_set.add(letter)20                    unique_set.add(letter)
21                if 'cost' in bush:21                if 'cost' in bush:
22                    result += bush['cost']22                    result += bush['cost']
23    return result23    return result
2424
2525
26def function_that_says_ni(*args, **kwargs):26def function_that_says_ni(*args, **kwargs):
27    price = 0.0027    price = 0.00
28    price += sum_positional_bush_price(*args)28    price += sum_positional_bush_price(*args)
29    29    
30    unique_set = set()30    unique_set = set()
31    price += sum_naming_bush_price(unique_set, **kwargs)31    price += sum_naming_bush_price(unique_set, **kwargs)
3232
33    price_in_int = int(price)33    price_in_int = int(price)
34    if 0 < price_in_int <= 42:34    if 0 < price_in_int <= 42:
35        if len(unique_set) % price_in_int == 0:35        if len(unique_set) % price_in_int == 0:
36            return f"{price:.2f}лв"36            return f"{price:.2f}лв"
37        37        
38    return "Ni!"38    return "Ni!"
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

f1f1
2list_shrub = ["храст", "shrub", "bush"]2list_shrub = ["храст", "shrub", "bush"]
33
n4def positional_parameter(price, *args):n4def sum_positional_bush_price(*args):
5    result = 0
5    for item in args:6    for item in args:
n6        if type(item) == dict and 'name' in item.keys():n7        if type(item) == dict and 'name' in item:
7             if item['name'].lower() in list_shrub:8             if item['name'].lower() in list_shrub:
n8                if 'cost' in item.keys():n9                result += item.get('cost', 0)
9                    price += item['cost']
1010
n11    return pricen11    return result
1212
nn13 
13def naming_parameter(priceunique_set, **kwargs):14def sum_naming_bush_price(unique_set, **kwargs):
15    result = 0
14    for name, bush in kwargs.items():16    for name, bush in kwargs.items():
n15        if type(bush) == dict and 'name' in bush.keys():n17        if type(bush) == dict and 'name' in bush:
16            if bush['name'].lower() in list_shrub:18            if bush['name'].lower() in list_shrub:
17                for letter in name:19                for letter in name:
18                    unique_set.add(letter)20                    unique_set.add(letter)
n19                if 'cost' in bush.keys():n21                if 'cost' in bush:
20                    price += bush['cost']22                    result += bush['cost']
21    return price23    return result
2224
2325
24def function_that_says_ni(*args, **kwargs):26def function_that_says_ni(*args, **kwargs):
25    price = 0.0027    price = 0.00
n26    price = positional_parameter(price, *args)n28    price += sum_positional_bush_price(*args)
27    29    
28    unique_set = set()30    unique_set = set()
n29    price = naming_parameter(priceunique_set, **kwargs)n31    price +sum_naming_bush_price(unique_set, **kwargs)
3032
31    price_in_int = int(price)33    price_in_int = int(price)
32    if 0 < price_in_int <= 42:34    if 0 < price_in_int <= 42:
33        if len(unique_set) % price_in_int == 0:35        if len(unique_set) % price_in_int == 0:
34            return f"{price:.2f}лв"36            return f"{price:.2f}лв"
35        37        
36    return "Ni!"38    return "Ni!"
t37 t
38 
39    
40 
41 
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op