From feb92564b29b578813d26151e3185d415dc183e0 Mon Sep 17 00:00:00 2001 From: MexTest Date: Fri, 13 Jan 2023 07:50:03 +0000 Subject: [PATCH 1/3] =?UTF-8?q?=D0=97=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=B8?= =?UTF-8?q?=D0=BB(=D0=B0)=20=D1=84=D0=B0=D0=B9=D0=BB=D1=8B=20=D0=B2=20''?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- task2.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 task2.py diff --git a/task2.py b/task2.py new file mode 100644 index 0000000..a2c4716 --- /dev/null +++ b/task2.py @@ -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) -- 2.36.2 From 2c865b78b11817e70207d9aa85bb929c7b7e8170 Mon Sep 17 00:00:00 2001 From: MexTest Date: Fri, 13 Jan 2023 07:54:19 +0000 Subject: [PATCH 2/3] - MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Исправление задачи (генератор простых чисел) с дня пересдачи (10.01.2023) --- prime_gen004(change).py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 prime_gen004(change).py diff --git a/prime_gen004(change).py b/prime_gen004(change).py new file mode 100644 index 0000000..36fa2fc --- /dev/null +++ b/prime_gen004(change).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=", ") -- 2.36.2 From 27bdd6d34abcc67bde6156b92fbed7b4694021be Mon Sep 17 00:00:00 2001 From: MexTest Date: Fri, 13 Jan 2023 10:31:00 +0000 Subject: [PATCH 3/3] - --- task1.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 task1.py diff --git a/task1.py b/task1.py new file mode 100644 index 0000000..211f06b --- /dev/null +++ b/task1.py @@ -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 -- 2.36.2