Решение на Генератори и итератори от Васил Малчев

Обратно към всички решения

Към профила на Васил Малчев

Резултати

  • 1 точка от тестове
  • 0 бонус точки
  • 1 точка общо
  • 2 успешни тест(а)
  • 12 неуспешни тест(а)

Код

def fibonacci():
a, b = 0, 1
for num in count(1, 1):
a, b = b, a+b
yield a
def primes():
for num in count(2, 1):
for div in range(2, int(math.sqrt(num) + 1)):
if num % div == 0:
break;
if div == int(math.sqrt(num)):
yield num
def alphabet(code='', letters=''):
if code is not '' and letters :
letters = {'bg': [],
'lat':['a','b','c','d']
}
return iter(letters[code])
return iter(letters)

Лог от изпълнението

E..EEEEEEEEEEE
======================================================================
ERROR: test_bg_alphabet (test.TestAlphabet)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_lat_alphabet (test.TestAlphabet)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_fibonacci (test.TestFibonacci)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_longer_sequence (test.TestFibonacci)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_generator_definitions (test.TestIntertwine)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_infinite_intertwined (test.TestIntertwine)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_intertwine (test.TestIntertwine)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_intertwine_repeating_builtin (test.TestIntertwine)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_kwargs_generator (test.TestIntertwine)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_repeating_with_different_args (test.TestIntertwine)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_for_larger_prime (test.TestPrimes)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_primes (test.TestPrimes)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

----------------------------------------------------------------------
Ran 14 tests in 24.141s

FAILED (errors=12)

История (1 версия и 0 коментара)

Васил обнови решението на 03.04.2015 16:57 (преди над 9 години)

+def fibonacci():
+ a, b = 0, 1
+ for num in count(1, 1):
+ a, b = b, a+b
+ yield a
+
+
+def primes():
+ for num in count(2, 1):
+ for div in range(2, int(math.sqrt(num) + 1)):
+ if num % div == 0:
+ break;
+ if div == int(math.sqrt(num)):
+ yield num
+
+
+def alphabet(code='', letters=''):
+ if code is not '' and letters :
+ letters = {'bg': [],
+ 'lat':['a','b','c','d']
+ }
+ return iter(letters[code])
+ return iter(letters)