1def function_that_says_ni(*args, **kwargs):
2 correct_bush_names = ["храст", "shrub", "bush"]
3 total_sum = 0
4
5 for arg in list(args) + list(kwargs.values()):
6 if type(arg) is not dict:
7 continue
8
9 if "name" not in arg:
10 continue
11
12 if arg["name"].lower() not in correct_bush_names:
13 continue
14
15 total_sum += arg["cost"] if "cost" in arg else 0
16
17 unique_word_count = len(set([
18 c for word in [
19 key for key, value in kwargs.items() if "name" in value and value["name"].lower() in correct_bush_names
20 ] for c in word])
21 )
22
23 if total_sum == 0 or total_sum > 42 or unique_word_count % int(total_sum) != 0:
24 return "Ni!"
25
26 return f"{total_sum:.2f}лв"
..E.......
======================================================================
ERROR: test_cost_whole_part_zero (test.TestNi.test_cost_whole_part_zero)
Test with a total cost part equal to zero.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 43, in test_cost_whole_part_zero
self.assertEqual(function_that_says_ni({'name': 'shrub', 'cost': 0.1},
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/solution.py", line 23, in function_that_says_ni
if total_sum == 0 or total_sum > 42 or unique_word_count % int(total_sum) != 0:
~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
ZeroDivisionError: integer modulo by zero
----------------------------------------------------------------------
Ran 10 tests in 0.001s
FAILED (errors=1)
Асен Красимиров
17.10.2024 15:06Извинявам се. От условиете разбрах, че се иска функцията да отпечата вярната стойност, не да я върне. Иначе да, разбирам, че по този начин функцията връща None.
|
f | 1 | def function_that_says_ni(*args, **kwargs): | f | 1 | def function_that_says_ni(*args, **kwargs): |
2 | correct_bush_names = ["храст", "shrub", "bush"] | 2 | correct_bush_names = ["храст", "shrub", "bush"] | ||
3 | total_sum = 0 | 3 | total_sum = 0 | ||
4 | 4 | ||||
5 | for arg in list(args) + list(kwargs.values()): | 5 | for arg in list(args) + list(kwargs.values()): | ||
6 | if type(arg) is not dict: | 6 | if type(arg) is not dict: | ||
7 | continue | 7 | continue | ||
8 | 8 | ||||
9 | if "name" not in arg: | 9 | if "name" not in arg: | ||
10 | continue | 10 | continue | ||
11 | 11 | ||||
12 | if arg["name"].lower() not in correct_bush_names: | 12 | if arg["name"].lower() not in correct_bush_names: | ||
13 | continue | 13 | continue | ||
14 | 14 | ||||
15 | total_sum += arg["cost"] if "cost" in arg else 0 | 15 | total_sum += arg["cost"] if "cost" in arg else 0 | ||
16 | 16 | ||||
n | 17 | unique_word_count = len( | n | 17 | unique_word_count = len(set([ |
18 | set( | ||||
19 | [ | ||||
20 | c for word in [ | 18 | c for word in [ | ||
21 | key for key, value in kwargs.items() if "name" in value and value["name"].lower() in correct_bush_names | 19 | key for key, value in kwargs.items() if "name" in value and value["name"].lower() in correct_bush_names | ||
22 | ] | ||||
23 | for c in word | 20 | ] for c in word]) | ||
24 | ] | ||||
25 | ) | ||||
26 | ) | 21 | ) | ||
27 | 22 | ||||
28 | if total_sum == 0 or total_sum > 42 or unique_word_count % int(total_sum) != 0: | 23 | if total_sum == 0 or total_sum > 42 or unique_word_count % int(total_sum) != 0: | ||
n | 29 | print("Ni!") | n | ||
30 | return | 24 | return "Ni!" | ||
31 | 25 | ||||
t | 32 | print(f"{total_sum:.2f}лв") | t | 26 | return f"{total_sum:.2f}лв" |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|