Решение на Генератори и итератори от Симона Найденова

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

Към профила на Симона Найденова

Резултати

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

Код

def fibonacci():
x = 0
y = 1
yield y
while True:
x, y = y, x + y
yield y
def primes():
x = 2
yield x
x = x + 1
def isPrime(x):
for i in range(2,x):
if x%i == 0:
return False
return True
while True:
if isPrime(x) == True:
yield x
x = x + 1
else:
x = x + 1
def alphabet(code = None, letters = None):
if code != None and letters == None:
the_alphabets = {'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': ['а','б','в','г','д','е','ж','з','и','й','к','л','м','н','о','п','р','с','т','у','ф','х','ц','ч','ш','щ','ъ','ь','ю','я']}
a = the_alphabets[str(code)]
while True:
for x in range(len(a) + 1):
yield a[x]
if letters != None:
a = [eachLetter for eachLetter in letters]
while True:
for x in range(len(a) + 1):
yield a[x]

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

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

FAILED (errors=7)

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

Симона обнови решението на 03.04.2015 04:10 (преди над 9 години)

+def fibonacci():
+ x = 0
+ y = 1
+ yield y
+ while True:
+ x, y = y, x + y
+ yield y
+
+
+def primes():
+ x = 2
+ yield x
+ x = x + 1
+ def isPrime(x):
+ for i in range(2,x):
+ if x%i == 0:
+ return False
+ return True
+ while True:
+ if isPrime(x) == True:
+ yield x
+ x = x + 1
+ else:
+ x = x + 1
+
+
+def alphabet(code = None, letters = None):
+ if code != None and letters == None:
+ the_alphabets = {'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': ['а','б','в','г','д','е','ж','з','и','й','к','л','м','н','о','п','р','с','т','у','ф','х','ц','ч','ш','щ','ъ','ь','ю','я']}
+ a = the_alphabets[str(code)]
+ while True:
+ for x in range(len(a) + 1):
+ yield a[x]
+ if letters != None:
+ a = [eachLetter for eachLetter in letters]
+ while True:
+ for x in range(len(a) + 1):
+ yield a[x]