Решение на Генератори и итератори от Димитрина Гецкова

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

Към профила на Димитрина Гецкова

Резултати

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

Код

def fibonacci():
a, b = 0, 1
while True:
print(b)
yield b
a, b = b, a + b
# fib = fibonacci_numbers()
# next(fib)
def sum_of_divisors(n):
return sum([x for x in range(1, n + 1) if n % x == 0])
def primes():
first = 2
while True:
if sum_of_divisors(first) == first + 1:
print(first)
yield first
first += 1
# prime = prime_numbers()
# next(prime)
def alphabet(code='', letters=''):
current = 0
lat = 'abcdefghijklmnopqrstuvwxyz'
bg = u"абвгдежзийклмнопрстуфхцчшщъьюя"
if letters != '':
while current < len(letters):
for x in letters:
current += 1
# print(current)
# print(x)
yield x
if code == 'lat':
while current < len(lat):
for x in lat:
current += 1
# print(x)
yield x
if code == 'bg':
while current < len(bg):
for x in bg:
current += 1
# print(x)
yield x

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

.E....EEEEEEE.
======================================================================
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

======================================================================
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

----------------------------------------------------------------------
Ran 14 tests in 16.423s

FAILED (errors=8)

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

Димитрина обнови решението на 03.04.2015 15:41 (преди над 9 години)

+def fibonacci():
+ a, b = 0, 1
+ while True:
+ print(b)
+ yield b
+ a, b = b, a + b
+
+# fib = fibonacci_numbers()
+# next(fib)
+
+
+def sum_of_divisors(n):
+ return sum([x for x in range(1, n + 1) if n % x == 0])
+
+
+def primes():
+ first = 2
+ while True:
+ if sum_of_divisors(first) == first + 1:
+ print(first)
+ yield first
+ first += 1
+
+# prime = prime_numbers()
+# next(prime)
+
+
+def alphabet(code='', letters=''):
+ current = 0
+ lat = 'abcdefghijklmnopqrstuvwxyz'
+ bg = u"абвгдежзийклмнопрстуфхцчшщъьюя"
+ if letters != '':
+ while current < len(letters):
+ for x in letters:
+ current += 1
+ # print(current)
+ # print(x)
+ yield x
+ if code == 'lat':
+ while current < len(lat):
+ for x in lat:
+ current += 1
+ # print(x)
+ yield x
+ if code == 'bg':
+ while current < len(bg):
+ for x in bg:
+ current += 1
+ # print(x)
+ yield x