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

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

5 точки общо

5 успешни теста
5 неуспешни теста
Код (Поправих своите грехове)

 1def not_too_expensive(price):
 2    return price<=42 and price>=0
 3
 4def unique_names(**kwargs):
 5    unique_chars = set()
 6    for key in kwargs.keys():
 7        unique_chars.update(key)
 8    return len(unique_chars)
 9
10def one_that_looks_nice(price,**kwargs):
11    return unique_names(**kwargs) % int(price) == 0
12
13def function_that_says_ni(*args, **kwargs):
14    for value in kwargs.values():
15        if "name" in value and "cost" in value:
16            if (value["name"].lower() in appropriate_answer) and (not_too_expensive(value["cost"]) and one_that_looks_nice(value["cost"],**kwargs)):
17                return round(float(value["cost"]),2)
18    return "Ni!"
19
20appropriate_answer=("храст", "shrub", "bush")

FE...FF.F.
======================================================================
ERROR: test_combination_of_arguments (test.TestNi.test_combination_of_arguments)
Test with combination of named and positional arguments.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 60, in test_combination_of_arguments
self.assertEqual(function_that_says_ni({'name': 'bush', 'cost': 1},
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/solution.py", line 16, in function_that_says_ni
if (value["name"].lower() in appropriate_answer) and (not_too_expensive(value["cost"]) and one_that_looks_nice(value["cost"],**kwargs)):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/solution.py", line 11, in one_that_looks_nice
return unique_names(**kwargs) % int(price) == 0
~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
ZeroDivisionError: integer modulo by zero

======================================================================
FAIL: test_all_possible_shrub_strings (test.TestNi.test_all_possible_shrub_strings)
Test with all possible strings that define a shrub.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 21, in test_all_possible_shrub_strings
self.assertEqual(function_that_says_ni({'name': 'shrub', 'cost': 1}), '1.00лв')
AssertionError: 'Ni!' != '1.00лв'
- Ni!
+ 1.00лв

======================================================================
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лв

======================================================================
FAIL: test_named_arguments (test.TestNi.test_named_arguments)
Test with named arguments.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 50, in test_named_arguments
self.assertEqual(function_that_says_ni(_abcde={'name': 'shrub', 'cost': 2.82},
AssertionError: 'Ni!' != '7.33лв'
- Ni!
+ 7.33лв

======================================================================
FAIL: test_single_with_no_named_args (test.TestNi.test_single_with_no_named_args)
Test with a single shrub that is passed as positional argument.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 17, in test_single_with_no_named_args
self.assertEqual(function_that_says_ni({'name': 'shrub', 'cost': 3.12}), '3.12лв')
AssertionError: 'Ni!' != '3.12лв'
- Ni!
+ 3.12лв

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

FAILED (failures=4, errors=1)

Дискусия
Виктор Бечев
19.10.2024 23:11

Голям грях - индентацията ти е от табулации. Бързо, докато не е видял Жорката!
История

f1def not_too_expensive(price):f1def not_too_expensive(price):
n2        if price<=42 and price>=0:n2    return price<=42 and price>=0
3                return True
4        return False
5 
63
7def unique_names(**kwargs):4def unique_names(**kwargs):
n8        unique_chars = set()n5    unique_chars = set()
9        for key in kwargs.keys():6    for key in kwargs.keys():
10                unique_chars.update(key)7        unique_chars.update(key)
11        return len(unique_chars)8    return len(unique_chars)
129
13def one_that_looks_nice(price,**kwargs):10def one_that_looks_nice(price,**kwargs):
n14        if unique_names(**kwargs) % int(price) == 0:n11    return unique_names(**kwargs) % int(price) == 0
15                return True
16        return False
1712
18def function_that_says_ni(*args, **kwargs):13def function_that_says_ni(*args, **kwargs):
t19        for value in kwargs.values():t14    for value in kwargs.values():
20                if "name" in value and "cost" in value:15        if "name" in value and "cost" in value:
21                        for _ in appropriate_answer:
22                                if (value["name"].lower() == _) and (not_too_expensive(value["cost"]) and one_that_looks_nice(value["cost"],**kwargs)):16            if (value["name"].lower() in appropriate_answer) and (not_too_expensive(value["cost"]) and one_that_looks_nice(value["cost"],**kwargs)):
23                                        return round(float(value["cost"]),2)17                return round(float(value["cost"]),2)
24        return "Ni!"18    return "Ni!"
2519
26appropriate_answer=("храст", "shrub", "bush")20appropriate_answer=("храст", "shrub", "bush")
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

f1def not_too_expensive(price):f1def not_too_expensive(price):
2        if price<=42 and price>=0:2        if price<=42 and price>=0:
3                return True3                return True
4        return False4        return False
55
66
7def unique_names(**kwargs):7def unique_names(**kwargs):
8        unique_chars = set()8        unique_chars = set()
9        for key in kwargs.keys():9        for key in kwargs.keys():
10                unique_chars.update(key)10                unique_chars.update(key)
11        return len(unique_chars)11        return len(unique_chars)
1212
13def one_that_looks_nice(price,**kwargs):13def one_that_looks_nice(price,**kwargs):
n14        if unique_names(**kwargs) % price == 0:n14        if unique_names(**kwargs) % int(price) == 0:
15                return True15                return True
16        return False16        return False
1717
18def function_that_says_ni(*args, **kwargs):18def function_that_says_ni(*args, **kwargs):
19        for value in kwargs.values():19        for value in kwargs.values():
20                if "name" in value and "cost" in value:20                if "name" in value and "cost" in value:
21                        for _ in appropriate_answer:21                        for _ in appropriate_answer:
22                                if (value["name"].lower() == _) and (not_too_expensive(value["cost"]) and one_that_looks_nice(value["cost"],**kwargs)):22                                if (value["name"].lower() == _) and (not_too_expensive(value["cost"]) and one_that_looks_nice(value["cost"],**kwargs)):
t23                                        return value["cost"]t23                                        return round(float(value["cost"]),2)
24        return "Ni!"24        return "Ni!"
2525
26appropriate_answer=("храст", "shrub", "bush")26appropriate_answer=("храст", "shrub", "bush")
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op