Решение на Генератори и итератори от Деян Боиклиев

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

Към профила на Деян Боиклиев

Резултати

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

Код

from math import sqrt, ceil
def fibonacci():
previous = 0
current = 1
while True:
temp = previous
previous = current
current += temp
yield previous
def primes():
number = 2
while True:
if is_prime(number):
yield number
number += 1
def is_prime(number):
if number == 2:
return True
divisor = 2
root = ceil(sqrt(number))
while divisor <= root:
if number % divisor == 0:
return False
divisor += 1
return True
ALPHABETS = {
'lat': 'abcdefghijklmnopqrstuvwxyz',
'bg': 'абвгдежзийклмнопрстуфхцчшщъьюя'
}
def alphabet(code='', letters=''):
alphabet = letters
if code != '':
alphabet = ALPHABETS[code]
for letter in alphabet:
yield letter

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

......EEEEEE..
======================================================================
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 12.206s

FAILED (errors=6)

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

Деян обнови решението на 03.04.2015 16:09 (преди над 9 години)

+from math import sqrt, ceil
+
+def fibonacci():
+ previous = 0
+ current = 1
+ while True:
+ temp = previous
+ previous = current
+ current += temp
+ yield previous
+
+
+def primes():
+ number = 2
+ while True:
+ if is_prime(number):
+ yield number
+ number += 1
+
+
+def is_prime(number):
+ if number == 2:
+ return True
+ divisor = 2
+ root = ceil(sqrt(number))
+ while divisor <= root:
+ if number % divisor == 0:
+ return False
+ divisor += 1
+ return True
+
+
+ALPHABETS = {
+ 'lat': 'abcdefghijklmnopqrstuvwxyz',
+ 'bg': 'абвгдежзийклмнопрстуфхцчшщъьюя'
+}
+
+
+def alphabet(code='', letters=''):
+ alphabet = letters
+ if code != '':
+ alphabet = ALPHABETS[code]
+ for letter in alphabet:
+ yield letter