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

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

8 точки общо

8 успешни теста
2 неуспешни теста
Код
Скрий всички коментари

 1def function_that_says_ni(*args, **kargs):
 2    sumCost = 0 
 3    sumLen = 0 
 4    strOfNames = ''
 5
 6    for elements in args:
 7        if type(elements) is dict and 'name' in elements:
 8            if elements['name'].upper() == 'ХРАСТ' or elements['name'].upper() == 'SHRUB' or elements['name'].upper() == 'BUSH':
 9              if 'cost' in elements:
10                sumCost += elements['cost']
11
12    for elements in kargs:
13        if type(kargs[elements]) is dict and 'name' in kargs[elements]:
14          if kargs[elements]['name'].upper() == 'ХРАСТ' or kargs[elements]['name'].upper() == 'SHRUB' or kargs[elements]['name'].upper() == 'BUSH':
15            strOfNames+=elements
16            if 'cost' in kargs[elements]:
17               sumCost += kargs[elements]['cost']
18               
19    unique = []
20    
21    for x in range(0, len(strOfNames)):
22       if strOfNames[x] not in unique:
23          unique.append(strOfNames[x])
24
25    sumLen= len(unique)
26    
27    if sumCost > 0 and sumCost < 42.00 and sumLen % int(sumCost) == 0 :
28      result = f'{sumCost:.2f}' + 'лв'
29      return result
30    else: 
31        return 'Ni!'

..E..F....
======================================================================
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 27, in function_that_says_ni
if sumCost > 0 and sumCost < 42.00 and sumLen % int(sumCost) == 0 :
~~~~~~~^~~~~~~~~~~~~~
ZeroDivisionError: integer modulo by zero

======================================================================
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.002s

FAILED (failures=1, errors=1)

Дискусия
История
Това решение има само една версия.