Решение на Генератори и итератори от Любомир Гавадинов

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

Към профила на Любомир Гавадинов

Резултати

  • 5 точки от тестове
  • 0 бонус точки
  • 5 точки общо
  • 7 успешни тест(а)
  • 7 неуспешни тест(а)

Код

def fibonacci():
a = 0
b = 1
while True:
yield b
a, b = b, a + b
def primes():
num = 2
while True:
isPrime = True
for x in range(2, num):
if num % x == 0:
isPrime = False
break
if isPrime:
yield num
num += 1
LETTERS = {
'lat': ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'],
'bg': ['а', 'б', 'в', 'г', 'д', 'е', 'ж', 'з', 'и', 'й', 'к', 'л', 'м',
'н', 'о', 'п', 'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ч', 'ш', 'щ',
'ь', 'ъ', 'ю', 'я']
}
def alphabet(code='lat', letters=None):
if letters is None:
letters = LETTERS[code]
for letter in letters:
yield letter

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

E.....EEEEEE..
======================================================================
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_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

----------------------------------------------------------------------
Ran 14 tests in 15.569s

FAILED (errors=7)

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

Любомир обнови решението на 03.04.2015 14:51 (преди над 9 години)

+def fibonacci():
+ a = 0
+ b = 1
+ while True:
+ yield b
+ a, b = b, a + b
+
+
+def primes():
+ num = 2
+ while True:
+ isPrime = True
+ for x in range(2, num):
+ if num % x == 0:
+ isPrime = False
+ break
+
+ if isPrime:
+ yield num
+ num += 1
+
+
+LETTERS = {
+ 'lat': ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
+ 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'],
+ 'bg': ['а', 'б', 'в', 'г', 'д', 'е', 'ж', 'з', 'и', 'й', 'к', 'л', 'м',
+ 'н', 'о', 'п', 'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ч', 'ш', 'щ',
+ 'ь', 'ъ', 'ю', 'я']
+}
+
+
+def alphabet(code='lat', letters=None):
+ if letters is None:
+ letters = LETTERS[code]
+
+ for letter in letters:
+ yield letter