- Коректно
- 5 успешни тест(а)
- 0 неуспешни тест(а)
..... ---------------------------------------------------------------------- Ran 5 tests in 0.005s OK
Срокът за предаване на решения е отминал
В програмисткия свят числото 2 е много много важно. Числата степени на 2 (1, 2, 4, 8, 16.. и т.н.) също. Всяко положително число може да се представи като сбор от числа, които са степени на 2.
Да се напише функция def powers_of_two_remain(numbers), която приема списък от цели положителни числа и връща True или False.
Функцията разсъждава по следния начин:
На входа се подава списъка от числа (например [6, 10, 8, 3, 3])
създава нов списък, като представя числата чрез такива, които са степени на 2 и сбора им е равен на числото от списъка. Взима възможно най-големите числа степени на двойка:
[8] #=> [8]
[10] #=> [8, 2]
[7, 3] #=> [4, 2, 1, 2, 1]
[6, 10, 8, 3, 3] #=> [4, 2, 8, 2, 8, 2, 1, 2, 1]
Обръщаме внимание, че 10 може да се разбие като [2, 2, 2, 2, 2], но трябва да вземем най-големите възможни числа степени на 2 и за това задължително го разбиваме във вида [8, 2].
[4, 2, 8, 2, 8, 2, 1, 2, 1] #=> [4]
True. В противен случай False.Примери:
def powers_of_two_remain([]) #=> False
def powers_of_two_remain([7, 8]) #=> True
def powers_of_two_remain([4, 8, 12]) #=> False
..... ---------------------------------------------------------------------- Ran 5 tests in 0.005s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.005s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.005s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.006s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.006s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.006s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.005s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.006s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.006s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.005s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.006s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.006s OK
.FF.F
======================================================================
FAIL: test_empty_list_as_argument (test.TestNoNumbersRemain)
----------------------------------------------------------------------
Traceback (most recent call last):
File "lib/language/python/runner.py", line 60, in thread
raise it.exc_info[1]
File "lib/language/python/runner.py", line 48, in run
self.result = func(*args, **kwargs)
File "/tmp/d20150321-24164-siiec4/test.py", line 54, in test_empty_list_as_argument
solution.powers_of_two_remain([])
AssertionError: True is not false
======================================================================
FAIL: test_power_of_two_remain_no_numbers_remain (test.TestNoNumbersRemain)
----------------------------------------------------------------------
Traceback (most recent call last):
File "lib/language/python/runner.py", line 60, in thread
raise it.exc_info[1]
File "lib/language/python/runner.py", line 48, in run
self.result = func(*args, **kwargs)
File "/tmp/d20150321-24164-siiec4/test.py", line 16, in test_power_of_two_remain_no_numbers_remain
solution.powers_of_two_remain([1, 2, 8, 15, 15, 10, 1, 2, 4, 7, 1])
AssertionError: True is not false
======================================================================
FAIL: test_two_same_numbers_always_false (test.TestNoNumbersRemain)
----------------------------------------------------------------------
Traceback (most recent call last):
File "lib/language/python/runner.py", line 60, in thread
raise it.exc_info[1]
File "lib/language/python/runner.py", line 48, in run
self.result = func(*args, **kwargs)
File "/tmp/d20150321-24164-siiec4/test.py", line 40, in test_two_same_numbers_always_false
solution.powers_of_two_remain([8, 8])
AssertionError: True is not false
----------------------------------------------------------------------
Ran 5 tests in 0.009s
FAILED (failures=3)
..... ---------------------------------------------------------------------- Ran 5 tests in 0.006s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.006s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.006s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.005s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.005s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.006s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.006s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.005s OK
.FF.F
======================================================================
FAIL: test_empty_list_as_argument (test.TestNoNumbersRemain)
----------------------------------------------------------------------
Traceback (most recent call last):
File "lib/language/python/runner.py", line 60, in thread
raise it.exc_info[1]
File "lib/language/python/runner.py", line 48, in run
self.result = func(*args, **kwargs)
File "/tmp/d20150321-24164-1x2nl9w/test.py", line 54, in test_empty_list_as_argument
solution.powers_of_two_remain([])
AssertionError: 'False' is not false
======================================================================
FAIL: test_power_of_two_remain_no_numbers_remain (test.TestNoNumbersRemain)
----------------------------------------------------------------------
Traceback (most recent call last):
File "lib/language/python/runner.py", line 60, in thread
raise it.exc_info[1]
File "lib/language/python/runner.py", line 48, in run
self.result = func(*args, **kwargs)
File "/tmp/d20150321-24164-1x2nl9w/test.py", line 16, in test_power_of_two_remain_no_numbers_remain
solution.powers_of_two_remain([1, 2, 8, 15, 15, 10, 1, 2, 4, 7, 1])
AssertionError: 'False' is not false
======================================================================
FAIL: test_two_same_numbers_always_false (test.TestNoNumbersRemain)
----------------------------------------------------------------------
Traceback (most recent call last):
File "lib/language/python/runner.py", line 60, in thread
raise it.exc_info[1]
File "lib/language/python/runner.py", line 48, in run
self.result = func(*args, **kwargs)
File "/tmp/d20150321-24164-1x2nl9w/test.py", line 40, in test_two_same_numbers_always_false
solution.powers_of_two_remain([8, 8])
AssertionError: 'False' is not false
----------------------------------------------------------------------
Ran 5 tests in 0.008s
FAILED (failures=3)
..... ---------------------------------------------------------------------- Ran 5 tests in 0.006s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.005s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.006s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.006s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.006s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.006s OK
...F.
======================================================================
FAIL: test_power_of_two_remain_numbers_do_remain (test.TestNoNumbersRemain)
----------------------------------------------------------------------
Traceback (most recent call last):
File "lib/language/python/runner.py", line 60, in thread
raise it.exc_info[1]
File "lib/language/python/runner.py", line 48, in run
self.result = func(*args, **kwargs)
File "/tmp/d20150321-24164-19sqzrz/test.py", line 27, in test_power_of_two_remain_numbers_do_remain
solution.powers_of_two_remain([1, 2, 8, 15, 15, 10, 1, 2, 4, 1])
AssertionError: False is not true
----------------------------------------------------------------------
Ran 5 tests in 0.006s
FAILED (failures=1)
..... ---------------------------------------------------------------------- Ran 5 tests in 0.006s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.006s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.007s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.193s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.007s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.007s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.007s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.006s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.007s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.006s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.005s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.005s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.007s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.005s OK
....F
======================================================================
FAIL: test_two_same_numbers_always_false (test.TestNoNumbersRemain)
----------------------------------------------------------------------
Traceback (most recent call last):
File "lib/language/python/runner.py", line 60, in thread
raise it.exc_info[1]
File "lib/language/python/runner.py", line 48, in run
self.result = func(*args, **kwargs)
File "/tmp/d20150321-24164-1vyjmcm/test.py", line 43, in test_two_same_numbers_always_false
solution.powers_of_two_remain([7, 7])
AssertionError: True is not false
----------------------------------------------------------------------
Ran 5 tests in 0.006s
FAILED (failures=1)
..... ---------------------------------------------------------------------- Ran 5 tests in 0.006s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.006s OK
..F.F
======================================================================
FAIL: test_power_of_two_remain_no_numbers_remain (test.TestNoNumbersRemain)
----------------------------------------------------------------------
Traceback (most recent call last):
File "lib/language/python/runner.py", line 60, in thread
raise it.exc_info[1]
File "lib/language/python/runner.py", line 48, in run
self.result = func(*args, **kwargs)
File "/tmp/d20150321-24164-1l6vyt2/test.py", line 16, in test_power_of_two_remain_no_numbers_remain
solution.powers_of_two_remain([1, 2, 8, 15, 15, 10, 1, 2, 4, 7, 1])
AssertionError: True is not false
======================================================================
FAIL: test_two_same_numbers_always_false (test.TestNoNumbersRemain)
----------------------------------------------------------------------
Traceback (most recent call last):
File "lib/language/python/runner.py", line 60, in thread
raise it.exc_info[1]
File "lib/language/python/runner.py", line 48, in run
self.result = func(*args, **kwargs)
File "/tmp/d20150321-24164-1l6vyt2/test.py", line 43, in test_two_same_numbers_always_false
solution.powers_of_two_remain([7, 7])
AssertionError: True is not false
----------------------------------------------------------------------
Ran 5 tests in 0.007s
FAILED (failures=2)
..... ---------------------------------------------------------------------- Ran 5 tests in 0.006s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.005s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.006s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.005s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.006s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.006s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.006s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.007s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.008s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.006s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.006s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.006s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.006s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.005s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.007s OK
EEEEE
======================================================================
ERROR: test_dont_break_down_power_of_two_numbers (test.TestNoNumbersRemain)
----------------------------------------------------------------------
Traceback (most recent call last):
File "lib/language/python/runner.py", line 60, in thread
raise it.exc_info[1]
File "lib/language/python/runner.py", line 48, in run
self.result = func(*args, **kwargs)
File "/tmp/d20150321-24164-1pswh5a/test.py", line 35, in test_dont_break_down_power_of_two_numbers
solution.powers_of_two_remain([8])
AttributeError: 'module' object has no attribute 'powers_of_two_remain'
======================================================================
ERROR: test_empty_list_as_argument (test.TestNoNumbersRemain)
----------------------------------------------------------------------
Traceback (most recent call last):
File "lib/language/python/runner.py", line 60, in thread
raise it.exc_info[1]
File "lib/language/python/runner.py", line 48, in run
self.result = func(*args, **kwargs)
File "/tmp/d20150321-24164-1pswh5a/test.py", line 54, in test_empty_list_as_argument
solution.powers_of_two_remain([])
AttributeError: 'module' object has no attribute 'powers_of_two_remain'
======================================================================
ERROR: test_power_of_two_remain_no_numbers_remain (test.TestNoNumbersRemain)
----------------------------------------------------------------------
Traceback (most recent call last):
File "lib/language/python/runner.py", line 60, in thread
raise it.exc_info[1]
File "lib/language/python/runner.py", line 48, in run
self.result = func(*args, **kwargs)
File "/tmp/d20150321-24164-1pswh5a/test.py", line 16, in test_power_of_two_remain_no_numbers_remain
solution.powers_of_two_remain([1, 2, 8, 15, 15, 10, 1, 2, 4, 7, 1])
AttributeError: 'module' object has no attribute 'powers_of_two_remain'
======================================================================
ERROR: test_power_of_two_remain_numbers_do_remain (test.TestNoNumbersRemain)
----------------------------------------------------------------------
Traceback (most recent call last):
File "lib/language/python/runner.py", line 60, in thread
raise it.exc_info[1]
File "lib/language/python/runner.py", line 48, in run
self.result = func(*args, **kwargs)
File "/tmp/d20150321-24164-1pswh5a/test.py", line 27, in test_power_of_two_remain_numbers_do_remain
solution.powers_of_two_remain([1, 2, 8, 15, 15, 10, 1, 2, 4, 1])
AttributeError: 'module' object has no attribute 'powers_of_two_remain'
======================================================================
ERROR: test_two_same_numbers_always_false (test.TestNoNumbersRemain)
----------------------------------------------------------------------
Traceback (most recent call last):
File "lib/language/python/runner.py", line 60, in thread
raise it.exc_info[1]
File "lib/language/python/runner.py", line 48, in run
self.result = func(*args, **kwargs)
File "/tmp/d20150321-24164-1pswh5a/test.py", line 40, in test_two_same_numbers_always_false
solution.powers_of_two_remain([8, 8])
AttributeError: 'module' object has no attribute 'powers_of_two_remain'
----------------------------------------------------------------------
Ran 5 tests in 0.007s
FAILED (errors=5)
FEF..
======================================================================
ERROR: test_empty_list_as_argument (test.TestNoNumbersRemain)
----------------------------------------------------------------------
Traceback (most recent call last):
File "lib/language/python/runner.py", line 60, in thread
raise it.exc_info[1]
File "lib/language/python/runner.py", line 48, in run
self.result = func(*args, **kwargs)
File "/tmp/d20150321-24164-1yiph40/test.py", line 54, in test_empty_list_as_argument
solution.powers_of_two_remain([])
File "/tmp/d20150321-24164-1yiph40/solution.py", line 6, in powers_of_two_remain
max_lizt = lizt[0]
IndexError: list index out of range
======================================================================
FAIL: test_dont_break_down_power_of_two_numbers (test.TestNoNumbersRemain)
----------------------------------------------------------------------
Traceback (most recent call last):
File "lib/language/python/runner.py", line 60, in thread
raise it.exc_info[1]
File "lib/language/python/runner.py", line 48, in run
self.result = func(*args, **kwargs)
File "/tmp/d20150321-24164-1yiph40/test.py", line 35, in test_dont_break_down_power_of_two_numbers
solution.powers_of_two_remain([8])
AssertionError: False is not true
======================================================================
FAIL: test_power_of_two_remain_no_numbers_remain (test.TestNoNumbersRemain)
----------------------------------------------------------------------
Traceback (most recent call last):
File "lib/language/python/runner.py", line 60, in thread
raise it.exc_info[1]
File "lib/language/python/runner.py", line 48, in run
self.result = func(*args, **kwargs)
File "/tmp/d20150321-24164-1yiph40/test.py", line 16, in test_power_of_two_remain_no_numbers_remain
solution.powers_of_two_remain([1, 2, 8, 15, 15, 10, 1, 2, 4, 7, 1])
AssertionError: True is not false
----------------------------------------------------------------------
Ran 5 tests in 0.008s
FAILED (failures=2, errors=1)
..... ---------------------------------------------------------------------- Ran 5 tests in 0.005s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.007s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.005s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.039s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.006s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.006s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.006s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.006s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.006s OK
....F
======================================================================
FAIL: test_two_same_numbers_always_false (test.TestNoNumbersRemain)
----------------------------------------------------------------------
Traceback (most recent call last):
File "lib/language/python/runner.py", line 60, in thread
raise it.exc_info[1]
File "lib/language/python/runner.py", line 48, in run
self.result = func(*args, **kwargs)
File "/tmp/d20150321-24164-14cs4l3/test.py", line 43, in test_two_same_numbers_always_false
solution.powers_of_two_remain([7, 7])
AssertionError: True is not false
----------------------------------------------------------------------
Ran 5 tests in 0.007s
FAILED (failures=1)
..... ---------------------------------------------------------------------- Ran 5 tests in 0.006s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.006s OK
....F
======================================================================
FAIL: test_two_same_numbers_always_false (test.TestNoNumbersRemain)
----------------------------------------------------------------------
Traceback (most recent call last):
File "lib/language/python/runner.py", line 60, in thread
raise it.exc_info[1]
File "lib/language/python/runner.py", line 48, in run
self.result = func(*args, **kwargs)
File "/tmp/d20150321-24164-1hmv4g7/test.py", line 43, in test_two_same_numbers_always_false
solution.powers_of_two_remain([7, 7])
AssertionError: True is not false
----------------------------------------------------------------------
Ran 5 tests in 0.007s
FAILED (failures=1)
..... ---------------------------------------------------------------------- Ran 5 tests in 0.006s OK
F.FFF
======================================================================
FAIL: test_dont_break_down_power_of_two_numbers (test.TestNoNumbersRemain)
----------------------------------------------------------------------
Traceback (most recent call last):
File "lib/language/python/runner.py", line 60, in thread
raise it.exc_info[1]
File "lib/language/python/runner.py", line 48, in run
self.result = func(*args, **kwargs)
File "/tmp/d20150321-24164-vyjq31/test.py", line 35, in test_dont_break_down_power_of_two_numbers
solution.powers_of_two_remain([8])
AssertionError: None is not true
======================================================================
FAIL: test_power_of_two_remain_no_numbers_remain (test.TestNoNumbersRemain)
----------------------------------------------------------------------
Traceback (most recent call last):
File "lib/language/python/runner.py", line 56, in thread
it._stop()
File "/home/pyfmi/Python-3.4.2/Lib/threading.py", line 990, in _stop
assert not lock.locked()
AssertionError
======================================================================
FAIL: test_power_of_two_remain_numbers_do_remain (test.TestNoNumbersRemain)
----------------------------------------------------------------------
Traceback (most recent call last):
File "lib/language/python/runner.py", line 56, in thread
it._stop()
File "/home/pyfmi/Python-3.4.2/Lib/threading.py", line 990, in _stop
assert not lock.locked()
AssertionError
======================================================================
FAIL: test_two_same_numbers_always_false (test.TestNoNumbersRemain)
----------------------------------------------------------------------
Traceback (most recent call last):
File "lib/language/python/runner.py", line 56, in thread
it._stop()
File "/home/pyfmi/Python-3.4.2/Lib/threading.py", line 990, in _stop
assert not lock.locked()
AssertionError
----------------------------------------------------------------------
Ran 5 tests in 6.215s
FAILED (failures=4)
..... ---------------------------------------------------------------------- Ran 5 tests in 0.007s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.007s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.006s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.006s OK
..... ---------------------------------------------------------------------- Ran 5 tests in 0.006s OK