1def function_that_says_ni(*args, **kwargs):
2 def valid_shrub(input_dict):
3 name = input_dict.get('name','').lower()
4 if name in ('храст', 'shrub', 'bush'):
5 return name in ('храст', 'shrub', 'bush')
6
7 total_cost = 0
8
9 def shrub_cost(input_dict):
10 return input_dict.get('cost', 0)
11
12 for shrub in args:
13 if valid_shrub(shrub):
14 total_cost += shrub_cost(shrub)
15
16 unique_letters = set()
17
18 for name, shrub in kwargs.items():
19 if valid_shrub(shrub):
20 total_cost += shrub_cost(shrub)
21 unique_letters.update(set(name))
22
23 if total_cost >= 42.00:
24 return 'Ni!'
25
26 if int(total_cost) == 0:
27 return "Ni!"
28
29 if (len(unique_letters) % int(total_cost)) == 0:
30 return '{:.2f}лв'.format(total_cost)
31 else:
32 return 'Ni!'
.....F.E..
======================================================================
ERROR: test_other_than_dicts (test.TestNi.test_other_than_dicts)
Test with inputs other than dicts.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 74, in test_other_than_dicts
self.assertEqual(function_that_says_ni(1, 3.14, ['some_list'], some_arg={1, 2, 3}), self.NI)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/solution.py", line 13, in function_that_says_ni
if valid_shrub(shrub):
^^^^^^^^^^^^^^^^^^
File "/tmp/solution.py", line 3, in valid_shrub
name = input_dict.get('name','').lower()
^^^^^^^^^^^^^^
AttributeError: 'int' object has no attribute 'get'
======================================================================
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 34, in test_multiple_shrubs_sumс
self.assertEqual(function_that_says_ni({'name': 'shrub', 'cost': 20.00},
AssertionError: 'Ni!' != '42.00лв'
- Ni!
+ 42.00лв
----------------------------------------------------------------------
Ran 10 tests in 0.001s
FAILED (failures=1, errors=1)
Георги Кунчев
22.10.2024 11:22За ";" в края на реда ще взимаме точки. Съветвам те да ги махнеш.
|
| f | 1 | def function_that_says_ni(*args, **kwargs): | f | 1 | def function_that_says_ni(*args, **kwargs): |
| 2 | def valid_shrub(input_dict): | 2 | def valid_shrub(input_dict): | ||
| 3 | name = input_dict.get('name','').lower() | 3 | name = input_dict.get('name','').lower() | ||
| 4 | if name in ('храст', 'shrub', 'bush'): | 4 | if name in ('храст', 'shrub', 'bush'): | ||
| 5 | return name in ('храст', 'shrub', 'bush') | 5 | return name in ('храст', 'shrub', 'bush') | ||
| 6 | 6 | ||||
| 7 | total_cost = 0 | 7 | total_cost = 0 | ||
| 8 | 8 | ||||
| 9 | def shrub_cost(input_dict): | 9 | def shrub_cost(input_dict): | ||
| 10 | return input_dict.get('cost', 0) | 10 | return input_dict.get('cost', 0) | ||
| 11 | 11 | ||||
| 12 | for shrub in args: | 12 | for shrub in args: | ||
| 13 | if valid_shrub(shrub): | 13 | if valid_shrub(shrub): | ||
| 14 | total_cost += shrub_cost(shrub) | 14 | total_cost += shrub_cost(shrub) | ||
| 15 | 15 | ||||
| 16 | unique_letters = set() | 16 | unique_letters = set() | ||
| 17 | 17 | ||||
| 18 | for name, shrub in kwargs.items(): | 18 | for name, shrub in kwargs.items(): | ||
| 19 | if valid_shrub(shrub): | 19 | if valid_shrub(shrub): | ||
| 20 | total_cost += shrub_cost(shrub) | 20 | total_cost += shrub_cost(shrub) | ||
| n | 21 | unique_letters.update(set(name)) | n | 21 | unique_letters.update(set(name)) |
| 22 | 22 | ||||
| 23 | if total_cost >= 42.00: | 23 | if total_cost >= 42.00: | ||
| 24 | return 'Ni!' | 24 | return 'Ni!' | ||
| 25 | 25 | ||||
| n | n | 26 | if int(total_cost) == 0: | ||
| 27 | return "Ni!" | ||||
| 28 | |||||
| 26 | if (len(unique_letters) % int(total_cost)) == 0: | 29 | if (len(unique_letters) % int(total_cost)) == 0: | ||
| t | 27 | return '{:.2f}лв.'.format(total_cost) | t | 30 | return '{:.2f}лв'.format(total_cost) |
| 28 | else: | 31 | else: | ||
| 29 | return 'Ni!' | 32 | return 'Ni!' |
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||
| f | 1 | def function_that_says_ni(*args, **kwargs): | f | 1 | def function_that_says_ni(*args, **kwargs): |
| 2 | def valid_shrub(input_dict): | 2 | def valid_shrub(input_dict): | ||
| 3 | name = input_dict.get('name','').lower() | 3 | name = input_dict.get('name','').lower() | ||
| 4 | if name in ('храст', 'shrub', 'bush'): | 4 | if name in ('храст', 'shrub', 'bush'): | ||
| 5 | return name in ('храст', 'shrub', 'bush') | 5 | return name in ('храст', 'shrub', 'bush') | ||
| 6 | 6 | ||||
| n | 7 | n | |||
| 8 | total_cost = 0 | 7 | total_cost = 0 | ||
| 9 | 8 | ||||
| 10 | def shrub_cost(input_dict): | 9 | def shrub_cost(input_dict): | ||
| 11 | return input_dict.get('cost', 0) | 10 | return input_dict.get('cost', 0) | ||
| 12 | 11 | ||||
| 13 | for shrub in args: | 12 | for shrub in args: | ||
| 14 | if valid_shrub(shrub): | 13 | if valid_shrub(shrub): | ||
| 15 | total_cost += shrub_cost(shrub) | 14 | total_cost += shrub_cost(shrub) | ||
| 16 | 15 | ||||
| 17 | unique_letters = set() | 16 | unique_letters = set() | ||
| 18 | 17 | ||||
| 19 | for name, shrub in kwargs.items(): | 18 | for name, shrub in kwargs.items(): | ||
| 20 | if valid_shrub(shrub): | 19 | if valid_shrub(shrub): | ||
| 21 | total_cost += shrub_cost(shrub) | 20 | total_cost += shrub_cost(shrub) | ||
| 22 | unique_letters.update(set(name)) | 21 | unique_letters.update(set(name)) | ||
| 23 | 22 | ||||
| 24 | if total_cost >= 42.00: | 23 | if total_cost >= 42.00: | ||
| 25 | return 'Ni!' | 24 | return 'Ni!' | ||
| 26 | 25 | ||||
| 27 | if (len(unique_letters) % int(total_cost)) == 0: | 26 | if (len(unique_letters) % int(total_cost)) == 0: | ||
| 28 | return '{:.2f}лв.'.format(total_cost) | 27 | return '{:.2f}лв.'.format(total_cost) | ||
| 29 | else: | 28 | else: | ||
| 30 | return 'Ni!' | 29 | return 'Ni!' | ||
| t | 31 | t | |||
| 32 | print(function_that_says_ni({"name": "храст", "cost": 120})) | ||||
| 33 | print(function_that_says_ni({"name": "храст", "cost": 1})) | ||||
| 34 | print(function_that_says_ni(aabcc={"name": "bush", "cost": 3.20})) |
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||
| f | 1 | def function_that_says_ni(*args, **kwargs): | f | 1 | def function_that_says_ni(*args, **kwargs): |
| n | 2 | def valid_shrub(dict): | n | 2 | def valid_shrub(input_dict): |
| 3 | name = dict.get('name','').lower() | 3 | name = input_dict.get('name','').lower() | ||
| 4 | if name == 'храст' or name == 'shrub' or name == 'bush': | 4 | if name in ('храст', 'shrub', 'bush'): | ||
| 5 | return True | 5 | return name in ('храст', 'shrub', 'bush') | ||
| 6 | return False; | 6 | |||
| 7 | 7 | ||||
| n | 8 | total_cost = 0.00; | n | 8 | total_cost = 0 |
| 9 | 9 | ||||
| n | 10 | def shrub_cost(dict): | n | 10 | def shrub_cost(input_dict): |
| 11 | cost = dict.get('cost', 0.00) | 11 | return input_dict.get('cost', 0) | ||
| 12 | return cost; | ||||
| 13 | 12 | ||||
| 14 | for shrub in args: | 13 | for shrub in args: | ||
| 15 | if valid_shrub(shrub): | 14 | if valid_shrub(shrub): | ||
| 16 | total_cost += shrub_cost(shrub) | 15 | total_cost += shrub_cost(shrub) | ||
| 17 | 16 | ||||
| 18 | unique_letters = set() | 17 | unique_letters = set() | ||
| 19 | 18 | ||||
| 20 | for name, shrub in kwargs.items(): | 19 | for name, shrub in kwargs.items(): | ||
| 21 | if valid_shrub(shrub): | 20 | if valid_shrub(shrub): | ||
| 22 | total_cost += shrub_cost(shrub) | 21 | total_cost += shrub_cost(shrub) | ||
| 23 | unique_letters.update(set(name)) | 22 | unique_letters.update(set(name)) | ||
| 24 | 23 | ||||
| 25 | if total_cost >= 42.00: | 24 | if total_cost >= 42.00: | ||
| 26 | return 'Ni!' | 25 | return 'Ni!' | ||
| 27 | 26 | ||||
| n | 28 | print('{}лв.'.format(total_cost, '.2f')) | n | ||
| 29 | |||||
| 30 | if (len(unique_letters) % int(total_cost)) == 0: | 27 | if (len(unique_letters) % int(total_cost)) == 0: | ||
| n | 31 | return '{:.2f}лв.'.format(total_cost) # не работи ПОМОЩ Т-Т | n | 28 | return '{:.2f}лв.'.format(total_cost) |
| 32 | else: | 29 | else: | ||
| 33 | return 'Ni!' | 30 | return 'Ni!' | ||
| t | t | 31 | |||
| 32 | print(function_that_says_ni({"name": "храст", "cost": 120})) | ||||
| 33 | print(function_that_says_ni({"name": "храст", "cost": 1})) | ||||
| 34 | print(function_that_says_ni(aabcc={"name": "bush", "cost": 3.20})) |
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||