supermaster-dev #1

Open
MexTest wants to merge 3 commits from supermaster-dev into supermaster
  1. 27
      prime_gen004(change).py
  2. 20
      task1.py
  3. 31
      task2.py

@ -0,0 +1,27 @@
def prime_generator(top = 0):
primes: list = []
number = 1
while number < top:
number += 1
if len(primes) == 0 and number == 2:
primes.append(number)
yield number
j = len(primes) - 1
while j >= 0:
if number % primes[j] == 0:
break
j -= 1
if j == -1:
primes.append(number)
yield number
'''Проверка выражений'''
prime_list = [n for n in prime_generator(258)]
prime_gen_object = (n for n in prime_generator(123))
print(prime_list)
print(prime_gen_object)
for i in prime_gen_object:
print(i, end=", ")

@ -0,0 +1,20 @@
def implicit_int(cls):
def wrapper(self, item):
if hasattr(object, item):
return object.__getattr__(self, attr)
else:
return 0
cls.__getattr__ = wrapper
return cls
'''Тесты'''
@implicit_int
class A:
x = -1
a = A()
print(a)
print(a.x)
print(a.e)
print(a.e + 589) # Вывод: 589

@ -0,0 +1,31 @@
import time
'''Вспомогательная функция для тестов'''
def Sum(m):
s = 0
for i in range(0, m):
s += i
return s
'''Менеджер контекста'''
class Timer():
def __init__(self):
self.start = None
def __enter__(self):
self.start = time.time()
return self
def __exit__(self, exc_type, exc_value, exc_traceback):
print(time.time() - self.start)
'''Проверка Менеджера контекста'''
with Timer():
with Timer():
print(Sum(1000))
with Timer():
print('sum: ' + str(Sum(10000000)), end=', time: ')
with Timer():
time.sleep(1.4)
Loading…
Cancel
Save