1def function_that_says_ni(*args, **kwargs):
2
3 BUSH_VALUES_LOWER = ("храст", "shrub", "bush")
4
5 summation = 0
6
7 used_letters = set();
8
9
10 for value in args:
11
12 if isinstance(value, dict) and isinstance(name := value.get("name"), str) and name.lower() in BUSH_VALUES_LOWER:
13
14 if(price := value.get("cost")):
15
16 summation += price
17
18
19 for key, value in kwargs.items():
20
21 if isinstance(value, dict) and isinstance(name := value.get("name"), str) and name.lower() in BUSH_VALUES_LOWER:
22
23 used_letters |= set(key)
24
25 if price := value.get("cost"):
26
27 summation += price
28
29 floored_price = int(summation)
30
31 is_valid_letter = lambda x: isinstance(x, str) and (x.islower() or x == '_')
32
33 number_of_unique_letters = sum(1 for letter in used_letters if is_valid_letter(letter))
34
35 if(summation > 42 or floored_price == 0 or number_of_unique_letters % floored_price != 0):
36 return "Ni!"
37
38
39 return f"{summation:.2f}лв"
..........
----------------------------------------------------------------------
Ran 10 tests in 0.000s
OK
f | 1 | def function_that_says_ni(*args, **kwargs): | f | 1 | def function_that_says_ni(*args, **kwargs): |
n | n | 2 | |||
2 | BUSH_VALUES_LOWER = ("храст", "shrub", "bush") | 3 | BUSH_VALUES_LOWER = ("храст", "shrub", "bush") | ||
n | n | 4 | |||
3 | summation = 0 | 5 | summation = 0 | ||
n | n | 6 | |||
4 | used_letters = set(); | 7 | used_letters = set(); | ||
5 | 8 | ||||
n | n | 9 | |||
6 | for value in args: | 10 | for value in args: | ||
n | n | 11 | |||
7 | if(isinstance(value, dict) and isinstance(name := value.get("name"), str) and name.lower() in BUSH_VALUES_LOWER): | 12 | if isinstance(value, dict) and isinstance(name := value.get("name"), str) and name.lower() in BUSH_VALUES_LOWER: | ||
13 | |||||
8 | if(price := value.get("cost")): | 14 | if(price := value.get("cost")): | ||
n | 9 | summation += price | n | 15 | |
10 | |||||
11 | for key, value in kwargs.items(): | ||||
12 | if(isinstance(value, dict) and isinstance(name := value.get("name"), str) and name.lower() in BUSH_VALUES_LOWER): | ||||
13 | used_letters |= set(key) | ||||
14 | if(price := value.get("cost")): | ||||
15 | summation += price | 16 | summation += price | ||
16 | 17 | ||||
n | 17 | if(summation > 42 or (floored_price := int(summation)) == 0 or (sum(1 for letter in used_letters if isinstance(letter, str) and (letter.islower() or letter == '_'))) % floored_price != 0): | n | 18 | |
19 | for key, value in kwargs.items(): | ||||
20 | |||||
21 | if isinstance(value, dict) and isinstance(name := value.get("name"), str) and name.lower() in BUSH_VALUES_LOWER: | ||||
22 | |||||
23 | used_letters |= set(key) | ||||
24 | |||||
25 | if price := value.get("cost"): | ||||
26 | |||||
27 | summation += price | ||||
28 | |||||
29 | floored_price = int(summation) | ||||
30 | |||||
31 | is_valid_letter = lambda x: isinstance(x, str) and (x.islower() or x == '_') | ||||
32 | |||||
33 | number_of_unique_letters = sum(1 for letter in used_letters if is_valid_letter(letter)) | ||||
34 | |||||
35 | if(summation > 42 or floored_price == 0 or number_of_unique_letters % floored_price != 0): | ||||
18 | return "Ni!" | 36 | return "Ni!" | ||
19 | 37 | ||||
t | t | 38 | |||
20 | return f"{summation:.2f}лв" | 39 | return f"{summation:.2f}лв" |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|