Решение на Генератори и итератори от Цветомир Цанов

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

Към профила на Цветомир Цанов

Резултати

  • 4 точки от тестове
  • 0 бонус точки
  • 4 точки общо
  • 6 успешни тест(а)
  • 8 неуспешни тест(а)

Код

def fibonacci():
a = 1
b = 1
while 1:
yield a
next_fib = a + b
a = b
b = next_fib
def primes():
a=2
yield a
a += 1
while 1:
isprime = True
for i in range(2,a):
if (a % i) == 0:
isprime = False
break
if isprime:
yield a
a += 1
def alphabet(code='other', letters=''):
if code == 'lat':
begin='a'
end='z'
elif code == 'bg':
begin = 'а'
end = 'я'
elif code == 'other':
begin = letters[0]
end = letters[-1]
beginNum = ord(begin)
endNum = ord(end)
for number in range(beginNum, endNum+1):
yield chr(number)

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

EE....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_endless_letters_generator (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 17.502s

FAILED (errors=8)

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

Цветомир обнови решението на 03.04.2015 09:10 (преди около 9 години)

+def fibonacci():
+ a = 1
+ b = 1
+ while 1:
+ yield a
+ next_fib = a + b
+ a = b
+ b = next_fib
+
+def primes():
+ a=2
+ yield a
+ a += 1
+ while 1:
+ isprime = True
+ for i in range(2,a):
+ if (a % i) == 0:
+ isprime = False
+ break
+ if isprime:
+ yield a
+ a += 1
+
+def alphabet(code='other', letters=''):
+ if code == 'lat':
+ begin='a'
+ end='z'
+ elif code == 'bg':
+ begin = 'а'
+ end = 'я'
+ elif code == 'other':
+ begin = letters[0]
+ end = letters[-1]
+
+ beginNum = ord(begin)
+ endNum = ord(end)
+ for number in range(beginNum, endNum+1):
+ yield chr(number)