diff --git a/Practice/GrishchenkoA/10.1.py b/Practice/GrishchenkoA/10.1.py new file mode 100644 index 0000000..fec6739 --- /dev/null +++ b/Practice/GrishchenkoA/10.1.py @@ -0,0 +1,4 @@ +lst = ["10", "5", "a", "3", "b"] +lst1 = [x**2 for z in lst if z.isdigit() and (x := int(z))%5 == 0] +print(lst1) + diff --git a/Practice/GrishchenkoA/10.2.py b/Practice/GrishchenkoA/10.2.py new file mode 100644 index 0000000..d1af75f --- /dev/null +++ b/Practice/GrishchenkoA/10.2.py @@ -0,0 +1,17 @@ +#-*- coding: utf-8 -*- +import random + +hello = ["Привет!", "Здравствуйте!", "Добрый день!"] +mood = ["Хорошо!", "Так себе", "Что-то не очень хорошо"] +weather = ["Сегодня ветренно", "Сегодня солнечно", "Дождь"] + +while True: + match input('Что Вы хотели спросить: '): + case "Привет": + print(random.choice(hello)) + case "Как дела?": + print(random.choice(mood)) + case "Какая сегодня погода": + print(random.choice(weather)) + case _: + print("Вопрос некорректен, попробуйте сформулировать его по-другому") diff --git a/Practice/GrishchenkoA/10.3.py b/Practice/GrishchenkoA/10.3.py new file mode 100644 index 0000000..e69de29 diff --git a/Practice/GrishchenkoA/11.1.py b/Practice/GrishchenkoA/11.1.py new file mode 100644 index 0000000..aadc1d5 --- /dev/null +++ b/Practice/GrishchenkoA/11.1.py @@ -0,0 +1,63 @@ +# -*- coding: utf-8 -*- + +import time +import threading +import multiprocessing + +def find_primes(*args): + if len(args) == 1: + start = 3 + end = args[0] + else: + start = args[0] + end = args[1] + + lst = [] + for i in range(start, end + 1): + if i > 1: + for y in range(2, i): + if i % y == 0: + break + else: + lst.append(i) + return lst + +if __name__ == "__main__": + lst_time = [] + start = time.perf_counter() + find_primes(10000) + find_primes(10001, 20000) + find_primes(20001, 30000) + + lst_time.append(time.perf_counter() - start) + print(f"Общее время обычного расчета занял в секундах: {lst_time}") + + start = time.perf_counter() # считаем что-то много раз с разными параметрами + lst_time1 = [] + thr1 = threading.Thread(target=find_primes, args=(10000,)) + thr2 = threading.Thread(target=find_primes, args=(10001, 20000)) + thr3 = threading.Thread(target=find_primes, args=(20001, 30000)) + thr1.start() # если 'забыть' выполнить start, то будет ошибка RuntimeError: cannot join thread before it is started + thr2.start() + thr3.start() + thr1.join() # если 'забыть' выполнить join, то ошибки не будет, но выполнится только один поток + thr2.join() + thr3.join() + lst_time1.append(time.perf_counter() - start) + print(f"Общее время расчета через многопоточность занял в секундах: {lst_time1}") + + start = time.perf_counter() + lst_time2 = [] + p1 = multiprocessing.Process(target=find_primes, args=(10000,)) + p2 = multiprocessing.Process(target=find_primes, args=(10001, 20000)) + p3 = multiprocessing.Process(target=find_primes, args=(20001, 30000)) + p1.start() # если 'забыть' выполнить start, то будет ошибка AssertionError: can only join a started process + p2.start() + p3.start() + p1.join() # если 'забыть' выполнить join, то ошибки не будет, но выполнится только один процесс + p2.join() + p3.join() + lst_time2.append(time.perf_counter() - start) + print(f"Общее время расчета через многопроцессорность занял в секундах: {lst_time2}") + +# Быстрее всего данная задача решается через многопоточность \ No newline at end of file diff --git a/Practice/GrishchenkoA/11.2.py b/Practice/GrishchenkoA/11.2.py new file mode 100644 index 0000000..5fd0b59 --- /dev/null +++ b/Practice/GrishchenkoA/11.2.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +from multiprocessing import Pool + +def addition(data): + t = data[0] + match t: + case int(t): + res = 0 + for y in data: + res += y + case str(t): + res = "" + for y in data: + res += y + case list(t): + res = [] + for y in data: + res += y + return res + + + +if __name__ == '__main__': + data = ([1, 2, 4], [[1, 2], [4, 7], [9, 0]], ["Hello", "world"]) + pool = Pool(processes=3) + res = pool.map(addition, data) + print(res) + diff --git a/Practice/GrishchenkoA/11.3.py b/Practice/GrishchenkoA/11.3.py new file mode 100644 index 0000000..e69de29 diff --git a/Practice/GrishchenkoA/12.1 k.py b/Practice/GrishchenkoA/12.1 k.py new file mode 100644 index 0000000..e69de29 diff --git a/Practice/GrishchenkoA/12.1.py b/Practice/GrishchenkoA/12.1.py new file mode 100644 index 0000000..4d73c07 --- /dev/null +++ b/Practice/GrishchenkoA/12.1.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +import socket +import pickle + + +s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +host = '192.168.1.35' +port = 64698 +s.bind((host, port)) +s.listen(2) +conn, addr = s.accept() +print('Server got connection from {}'.format(addr)) +while True: + data = conn.recv(1024) + if not data: + break + data1 = pickle.loads(data) + d = {"house": "дом", "car": "машина", "three": "дерево", "cat": "кошка", "apple": "яблоко"} + c = d.keys() + a = [] + for i in c: + for y in data1: + if y == i: + a.append(d[i]) + conn.send(pickle.dumps(a)) +conn.close() diff --git a/Practice/GrishchenkoA/2.1.py b/Practice/GrishchenkoA/2.1.py new file mode 100644 index 0000000..55e7ed7 --- /dev/null +++ b/Practice/GrishchenkoA/2.1.py @@ -0,0 +1,10 @@ +import math + + +def square(r): + return math.pi * r ** 2 + + +radius = input("Введите радиус: ") +result = square(int(radius)) +print(f"Площадь круга: {result}") diff --git a/Practice/GrishchenkoA/2.2.py b/Practice/GrishchenkoA/2.2.py new file mode 100644 index 0000000..07b8c02 --- /dev/null +++ b/Practice/GrishchenkoA/2.2.py @@ -0,0 +1,6 @@ +start = input("Топлива было: ") +end = input("Топлива осталось: ") +distance = input("Расстояние: ") +diff = int(start) - int(end) +result = diff / int(distance) +print(f"Средний расход бензина: {result}") \ No newline at end of file diff --git a/Practice/GrishchenkoA/3.1.py b/Practice/GrishchenkoA/3.1.py new file mode 100644 index 0000000..8cc6411 --- /dev/null +++ b/Practice/GrishchenkoA/3.1.py @@ -0,0 +1,4 @@ +a = int(input("Введите длину прямоугольника: ")) +b = int(input("Введите ширину прямоугольника: ")) +p = 2*(a + b) +print(f"Периметр прямоугольника: {p}") \ No newline at end of file diff --git a/Practice/GrishchenkoA/3.2.py b/Practice/GrishchenkoA/3.2.py new file mode 100644 index 0000000..c07ae85 --- /dev/null +++ b/Practice/GrishchenkoA/3.2.py @@ -0,0 +1,4 @@ +time = int(input("Введите время, проведенное в пути: ")) +distance = int(input("Введите пройденное расстояние: ")) +speed = distance / time +print(f"Средняя скорость автомобиля равна: {speed}") diff --git a/Practice/GrishchenkoA/3.3.1.py b/Practice/GrishchenkoA/3.3.1.py new file mode 100644 index 0000000..ec8831e --- /dev/null +++ b/Practice/GrishchenkoA/3.3.1.py @@ -0,0 +1,4 @@ +password = int(input("Введите пароль :")) +key = 888 +result = password ^ key +print(result) \ No newline at end of file diff --git a/Practice/GrishchenkoA/3.3.2.py b/Practice/GrishchenkoA/3.3.2.py new file mode 100644 index 0000000..8d992ce --- /dev/null +++ b/Practice/GrishchenkoA/3.3.2.py @@ -0,0 +1,4 @@ +code = int(input("Введите зашифрованный код :")) +key = 888 +password = code ^ key +print(password) \ No newline at end of file diff --git a/Practice/GrishchenkoA/3.4.py b/Practice/GrishchenkoA/3.4.py new file mode 100644 index 0000000..13e54a8 --- /dev/null +++ b/Practice/GrishchenkoA/3.4.py @@ -0,0 +1,4 @@ +word = input("Введите слово: ") +corrected_word = word.replace("А" , "*") +print(corrected_word) + diff --git a/Practice/GrishchenkoA/3.5.py b/Practice/GrishchenkoA/3.5.py new file mode 100644 index 0000000..375913a --- /dev/null +++ b/Practice/GrishchenkoA/3.5.py @@ -0,0 +1,7 @@ +word = input("Введите слово для проверки: ") +_lower = word.lower() +left = _lower +rights = _lower[::-1] +print(left == rights) + + diff --git a/Practice/GrishchenkoA/4.1.py b/Practice/GrishchenkoA/4.1.py new file mode 100644 index 0000000..05b0633 --- /dev/null +++ b/Practice/GrishchenkoA/4.1.py @@ -0,0 +1,11 @@ +number = 1 +while number <= 100: + if number % 15 == 0: + print("FizzBuzz") + elif number % 5 == 0: + print("Buzz") + elif number % 3 == 0: + print("Fizz") + else: + print(number) + number += 1 diff --git a/Practice/GrishchenkoA/4.2.py b/Practice/GrishchenkoA/4.2.py new file mode 100644 index 0000000..a7829ce --- /dev/null +++ b/Practice/GrishchenkoA/4.2.py @@ -0,0 +1,3 @@ +numbers = input("Введите пятизначное число: ") +for i, d in enumerate(numbers): + print(f"{i+1} цифра равна {d}") \ No newline at end of file diff --git a/Practice/GrishchenkoA/4.3.py b/Practice/GrishchenkoA/4.3.py new file mode 100644 index 0000000..e02ffdb --- /dev/null +++ b/Practice/GrishchenkoA/4.3.py @@ -0,0 +1,13 @@ +numbers="" +while (symbol := input("Введите числовой символ: ")).lower() != "stop": + if symbol.isdecimal(): + numbers += symbol + else: + print("Введен нечисловой символ") +else: + print(f"Сформированное число: {int(numbers)}") + + + + + diff --git a/Practice/GrishchenkoA/4.4.py b/Practice/GrishchenkoA/4.4.py new file mode 100644 index 0000000..3bcec3d --- /dev/null +++ b/Practice/GrishchenkoA/4.4.py @@ -0,0 +1,5 @@ +import random + +answer = ["Ты сам-то понял, что написал?", "Аргументируй", "И?"] +while (request := input("Введите запрос: ")) != "хватит": + print(random.choice(answer)) \ No newline at end of file diff --git a/Practice/GrishchenkoA/4.5.py b/Practice/GrishchenkoA/4.5.py new file mode 100644 index 0000000..810df3f --- /dev/null +++ b/Practice/GrishchenkoA/4.5.py @@ -0,0 +1,23 @@ +import random + +range = input("Введите диапазон чисел: ").split() +hidden_numbers = random.randint(int(range[0]), int(range[1])) +numbers_1 = input("Угадайте целое число: ") +while True: + if not numbers_1.isdigit(): + print("Вы ввели нечисловой символ") + break + else: + numbers_1 = int(numbers_1) + if numbers_1 < hidden_numbers: + print("Загаданное число больше введенного") + elif numbers_1 > hidden_numbers: + print("Загаданное число меньше введенного") + else: + print("Вы угадали") + break + numbers_1 = input("Угадайте целое число: ") + + + + diff --git a/Practice/GrishchenkoA/4.6.py b/Practice/GrishchenkoA/4.6.py new file mode 100644 index 0000000..c5e1081 --- /dev/null +++ b/Practice/GrishchenkoA/4.6.py @@ -0,0 +1,19 @@ +def choose_max(a, b): + if a > b: + max_1 = a + else: + max_1 = b + print(f"Большее число из введенных: {max_1}") + + +def finds_max(a, b): + if a > b: + max_2 = a + else: + max_2 = b + return max_2 + + +a, b = map(int, input("Введите два числа: ").split()) +choose_max(a, b) +finds_max(a, b) \ No newline at end of file diff --git a/Practice/GrishchenkoA/4.7.py b/Practice/GrishchenkoA/4.7.py new file mode 100644 index 0000000..5ba98ea --- /dev/null +++ b/Practice/GrishchenkoA/4.7.py @@ -0,0 +1,16 @@ +def decorator1(func): + def equality(*args, **kwargs): + print("===========") + res = func(*args, **kwargs) + print("===========") + return res + return equality + + +@decorator1 +def func(): + print("Привет") + +func() + + diff --git a/Practice/GrishchenkoA/4.8.py b/Practice/GrishchenkoA/4.8.py new file mode 100644 index 0000000..a58345b --- /dev/null +++ b/Practice/GrishchenkoA/4.8.py @@ -0,0 +1,29 @@ +import random + +play = ["камень", "ножницы", "бумага"] +while (player_1 := input("Введите ваш вариант: ").lower()) != "хватит": + player_2 = random.choice(play) + print(f"Вариант компьютера: {player_2}") + if player_1 == "камень": + if player_2 == "камень": + print("Ничья") + elif player_2 == "ножницы": + print("Вы выиграли") + elif player_2 == "бумага": + print("Вы проиграли") + elif player_1 == "ножницы": + + if player_2 == "камень": + print("Вы проиграли") + elif player_2 == "ножницы": + print("Ничья") + elif player_2 == "бумага": + print("Вы выиграли") + elif player_1 == "бумага": + + if player_2 == "камень": + print("Вы выиграли") + elif player_2 == "ножницы": + print("Вы проиграли") + elif player_2 == "бумага": + print("Ничья") \ No newline at end of file diff --git a/Practice/GrishchenkoA/5.1.py b/Practice/GrishchenkoA/5.1.py new file mode 100644 index 0000000..91b7356 --- /dev/null +++ b/Practice/GrishchenkoA/5.1.py @@ -0,0 +1,21 @@ +def find_min_index(lst): + for i,d in enumerate(lst): + d = min(lst[i:]) + d, lst[i] = lst[i], d + + +arr = [0, 3, 24, 2, 3, 7] +#for i in range(0, len(arr)): +find_min_index(arr) +print(arr) + +#def find_min_index(lst): + # a = min(lst[i:]) + # c = lst.index(a, i) + #lst[c], lst[i] = lst[i], lst[c] + + +#arr = [0, 3, 24, 2, 3, 7] +#for i in range(0, len(arr)): + # find_min_index(arr) +#print(arr) \ No newline at end of file diff --git a/Practice/GrishchenkoA/5.2.py b/Practice/GrishchenkoA/5.2.py new file mode 100644 index 0000000..422cdd9 --- /dev/null +++ b/Practice/GrishchenkoA/5.2.py @@ -0,0 +1,15 @@ +def repeat(lst): + set_new = set() + for i in lst: + if not i in set_new: + set_new.add(i) + else: + print(i) + return i + + +lst_new = [2, 3, 4, 5, 3, 2] +repeat(lst_new) + + + diff --git a/Practice/GrishchenkoA/5.3.py b/Practice/GrishchenkoA/5.3.py new file mode 100644 index 0000000..713883b --- /dev/null +++ b/Practice/GrishchenkoA/5.3.py @@ -0,0 +1,14 @@ +str_new = "Петров - 2 , Иванов - 5 , Сидоров - 4" +lst = list(str_new.split()) +dict_1 = {2: "неудовлетворительно", 3: "удовлетворительно", 4: "хорошо", 5: "отлично"} +for y, b in enumerate(lst): + if b.isdigit(): + b = int(b) + if b in dict_1: + lst[y] = dict_1[b] +str_1 = "" +for i in lst: + print(str_1.join(i), end=" ") + + + diff --git a/Practice/GrishchenkoA/5.4.py b/Practice/GrishchenkoA/5.4.py new file mode 100644 index 0000000..b38ab66 --- /dev/null +++ b/Practice/GrishchenkoA/5.4.py @@ -0,0 +1,19 @@ +def delete_column(lst, number): + for d in lst: + for y, v in enumerate(d): + if number == int(v): + for k in range(len(lst)): + del lst[k][y] + for y, v in enumerate(d): + if number == int(v): + for k in range(len(lst)): + del lst_1[k][y] + + +lst_1 = [[1, 2, 2, 4], [7, 8, 9, 5], [5, 6, 7, 4], [1, 2, 9, 5]] +number_1 = int(input("Введите цифру: ")) +delete_column(lst_1, number_1) +print(lst_1) + + + diff --git a/Practice/GrishchenkoA/5.5.py b/Practice/GrishchenkoA/5.5.py new file mode 100644 index 0000000..1ed3cab --- /dev/null +++ b/Practice/GrishchenkoA/5.5.py @@ -0,0 +1,17 @@ +text1 = open("text1.txt", "r") +text_read = text1.read() +text1.close() +request = input("Введите tab, если нужно заменить табуляцию на 4 пробела, если наоборот введите four: ") +text1 = open("text1.txt", "w") +if request == "tab": + text1.write(text_read.replace('\t', ' ')) +elif request == "four": + text1.write(text_read.replace(' ', '\t')) +else: + print("Неизвестный запрос") +text1.close() + + + + + diff --git a/Practice/GrishchenkoA/6.1.py b/Practice/GrishchenkoA/6.1.py new file mode 100644 index 0000000..ebe5f5d --- /dev/null +++ b/Practice/GrishchenkoA/6.1.py @@ -0,0 +1,26 @@ +class MyTanks: + "Класс содержит виды танков c характеристиками" + color = "green" + + + def __init__(self, damage, rate_of_fire, ammunition, speed, strength): + self.damage = damage + self.rate_of_fire = rate_of_fire + self.ammunition = ammunition + self.speed = speed + self.strength = strength + + @staticmethod + def print_res(lst): + for i in lst: + print(i.__dict__) + + +su_76i = MyTanks(156, 16, 170, 50, 285) +su_85i = MyTanks(280, 14, 70, 50, 500) +k_91_pt = MyTanks(530, 7, 30, 52, 1600) +print(MyTanks.__doc__) +lst_tanks = [su_76i, su_85i, k_91_pt] +MyTanks.print_res(lst_tanks) + + diff --git a/Practice/GrishchenkoA/6.2.py b/Practice/GrishchenkoA/6.2.py new file mode 100644 index 0000000..be1a5a8 --- /dev/null +++ b/Practice/GrishchenkoA/6.2.py @@ -0,0 +1,49 @@ +class Duck: + color = "grey" + def __init__(self, name, weight): + self.name = name + self.weight = weight + + + @staticmethod + def say_Duck(): + print("Crack") + + + @classmethod + def color_duck(cls): + print(f"Цвет уток: {Duck.color}") + + + def __repr__(self): + return f"Имя утки: {self.name}, вес утки: {self.weight} грамм" + + + def __lt__(self, other): + if self.weight < other.weight: + return other.name + else: + return self.name + + + def __ne__(self, other): + return self.weight != other.weight + + + def __add__(self, other): + return self.weight + other.weight + + + + +d1 = Duck("Billy", 700) +d2 = Duck("Willy", 900) +d3 = Duck("Dilly", 800) +d1.say_Duck() +Duck.color_duck() +print(repr(d1)) +print(repr(d2)) +print(repr(d3)) +print(f"Утка {d2 < d3} весит больше") +print(d1 != d2) +print(f"Вес двух уток равен {d1 + d3} грамм") diff --git a/Practice/GrishchenkoA/6.3.py b/Practice/GrishchenkoA/6.3.py new file mode 100644 index 0000000..365e68b --- /dev/null +++ b/Practice/GrishchenkoA/6.3.py @@ -0,0 +1,40 @@ +import tempfile +import os + + +class WrapStrToFile: + def __init__(self): + self.filepath = tempfile.mktemp() + + + @property + def content(self): + try: + with open(self.filepath, "r") as readfile: + file_1 = readfile.read() + return file_1 + except: + return "File doesn't exist" + + + @content.setter + def content(self, value): + try: + with open(self.filepath, "w") as writefile: + writefile.write(value) + except: + return "Error writing to file" + + + @content.deleter + def content(self): + os.remove(self.filepath) + + +wstf = WrapStrToFile() +print(wstf.content) +wstf.content = 'test str' +print(wstf.content) +wstf.content = 'text 2' +print(wstf.content) +del wstf.content diff --git a/Practice/GrishchenkoA/7.1.py b/Practice/GrishchenkoA/7.1.py new file mode 100644 index 0000000..43ab93b --- /dev/null +++ b/Practice/GrishchenkoA/7.1.py @@ -0,0 +1,13 @@ +class Man: + def __init__(self, name): + self.name = name + + def solve_task(self): + print("I'm not ready yet") + + +Man_1 = Man("Ivan") +Man_1.solve_task() +print(Man_1.name) + + diff --git a/Practice/GrishchenkoA/7.2.py b/Practice/GrishchenkoA/7.2.py new file mode 100644 index 0000000..b0e8ace --- /dev/null +++ b/Practice/GrishchenkoA/7.2.py @@ -0,0 +1,23 @@ +import random +import time + + +class Man: + def __init__(self, name): + self.name = name + + def solve_task(self): + print("I'm not ready yet") + + +class Pupil(Man): + def solve_task(self): + time_new = random.randint(3, 6) + res = time.sleep(time_new) + super().solve_task() + + +Pupill_1 = Pupil("Svetlana") +Man_1 = Man("Petr") +Pupill_1.solve_task() + diff --git a/Practice/GrishchenkoA/7.3.py b/Practice/GrishchenkoA/7.3.py new file mode 100644 index 0000000..23879d6 --- /dev/null +++ b/Practice/GrishchenkoA/7.3.py @@ -0,0 +1,72 @@ +# -*- coding: utf-8 -*- +class ATM: + def __init__(self, cash): + self._cash = cash + + def get_cash(self): + return self._cash + + def set_cash(self): + self._cash = cash + + +class SimpleATM(ATM): + def deposit_cash(money): + if type(money) is float: + return money + else: + print("Неверно введена сумма") + + def choice(self): + request = input("Выберите желаемую операцию: 1 - если хотите внести наличные, 2 - если хотите снять наличные: ") + if request == "1": + money = float(input("Введите сумму для внесения наличных на счет: ")) + self._cash = self._cash + money + print(f"На вашем счету теперь: {self._cash} рублей") + if request == "2": + money = float(input("Введите сумму, которую хотите снять со счета: ")) + if self._cash < money: + print("Недостаточно средств на счете") + else: + self._cash = self._cash - money + print(f"На вашем счету теперь: {self._cash} рублей") + return self._cash + + +class SuperATM(ATM): + def choice(self): + request = input("Выберите желаемую операцию: 1 - если хотите внести наличные, 2 - если хотите снять наличные, 3 - хотите оплатить онлайн: ") + + if request == "1": + money = float(input("Введите сумму для внесения наличных на счет: ")) + self._cash = self._cash + money + print(f"На вашем счету теперь: {self._cash} рублей") + + if request == "2": + money = float(input("Введите сумму, которую хотите снять со счета: ")) + if self._cash < money: + print("Недостаточно средств на счете") + else: + self._cash = self._cash - money + print(f"На вашем счету теперь: {self._cash} рублей") + + if request == "3": + money = float(input("Введите сумму для оплаты онлайн: ")) + if self._cash < money: + print("Недостаточно средств на счете") + else: + self._cash = self._cash - money + print(f"На вашем счету теперь: {self._cash} рублей") + return self._cash + + +# person_1 = SimpleATM(50000) +# person_1.choice() + +person_2 = SuperATM(52000) +person_2.choice() + + + + + diff --git a/Practice/GrishchenkoA/8.1.py b/Practice/GrishchenkoA/8.1.py new file mode 100644 index 0000000..4d51d22 --- /dev/null +++ b/Practice/GrishchenkoA/8.1.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +class IterRead: + def __init__(self, file_new, symbol): + self.file_new = file_new + self.symbol = symbol + self.ind = 0 + + + def __iter__(self): + return self + + def __next__(self): + text = "" + while self.ind != -1: + file.seek(self.ind) + txt = file.read(1) + if txt != self.symbol: + text += txt + else: + self.ind = file.tell() + return text + self.ind += 1 + if txt == "": + raise StopIteration + + def __del__(self): + self.file_new() + + +with open("text1.txt", "r") as file: + for i in IterRead(file, "~"): + print(i) + print("===============") \ No newline at end of file diff --git a/Practice/GrishchenkoA/8.2.py b/Practice/GrishchenkoA/8.2.py new file mode 100644 index 0000000..809338e --- /dev/null +++ b/Practice/GrishchenkoA/8.2.py @@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- +def read_line(file): + try: + with open(file, "r") as f: + for stroka in f: + yield stroka + except: + print("Ошибка при чтении файла") + + + +for i in read_line("text4.txt"): + print(i) + print("=======") \ No newline at end of file diff --git a/Practice/GrishchenkoA/8.3.py b/Practice/GrishchenkoA/8.3.py new file mode 100644 index 0000000..dc60a5c --- /dev/null +++ b/Practice/GrishchenkoA/8.3.py @@ -0,0 +1,14 @@ +import time + +class ManagerTime: + def __enter__(self): + self.start = time.time() + + def __exit__(self, exc_type, exc_val, exc_tb): + self.stop = time.time() - self.start + print(f"Время выполнения программы заняло: {self.stop} секунд") + + +with ManagerTime(): + for i in range(100000): + i += i \ No newline at end of file diff --git a/Practice/GrishchenkoA/8.4.py b/Practice/GrishchenkoA/8.4.py new file mode 100644 index 0000000..b472856 --- /dev/null +++ b/Practice/GrishchenkoA/8.4.py @@ -0,0 +1,18 @@ +import itertools + +t = ([1, 2, 3], [4, 5], [6, 7]) +lst = [] +f = itertools.chain(t) +for i in f: + lst += i +print(lst) + +c = ['hello', 'i', 'write', 'cool', 'code'] +l = itertools.filterfalse(lambda x: len(x) < 5, c) +lst1 = list(l) +print(lst1) + +d = 'password' +v = itertools.combinations_with_replacement(d, 4) +print(list(v)) + diff --git a/Practice/GrishchenkoA/9.1.py b/Practice/GrishchenkoA/9.1.py new file mode 100644 index 0000000..55e99e2 --- /dev/null +++ b/Practice/GrishchenkoA/9.1.py @@ -0,0 +1,26 @@ +#-*- coding: utf-8 -*- +import re + +st = re.compile(r"git [a-z]{3,4} \Z|git [a-z]{4,8} \W+[a-z]{1,3}\W+[a-z]{2,8}.[a-z]{6}|git [a-z]{4,8}.{55}|git [a-z]{3,4} [a-z]{6}.?[a-z]{2,4}|git [a-z]{3,4}") +with open(r"../README.md", encoding="utf") as f: + txt = f.read() + +res1 = re.findall(st, txt) +print(res1) + + + + + + + + +#git clone https://github.com/IlyaOrlov/PythonCourse2.0_August22.git "git [a-z]{4,8}\W{55}git +#git checkout -b my_branch "git [a-z]{4,8} \W+[a-z]{1,3}\W+[a-z]{2,8}.[a-z]{6}" +#git push --set-upstream origin my_branch git [a-z]{4,8} \W+[a-z]{1,3}\W+[a-z]{2,8}.[a-z]{6} my_branch" +#git commit -m "Любой разумный комментарий к сделанным изменениям" r"git [a-z]{4,8} \W+[a-z]{1,3}\W" +#git@github.com:IlyaOrlov/PythonCourse2.0_August22.git r"git.?[a-z]{6}.[a-z]{3}.{39}" +#git push r"git [a-z]{3,4} +#git add +#git add mytest.py r"git [a-z]{3,4} [a-z]{6}.?[a-z]{2,4} +#git pull origin main r"git \ No newline at end of file diff --git a/Practice/GrishchenkoA/9.2.py b/Practice/GrishchenkoA/9.2.py new file mode 100644 index 0000000..9f3c8d1 --- /dev/null +++ b/Practice/GrishchenkoA/9.2.py @@ -0,0 +1,18 @@ +# #-*- coding: utf-8 -*- +import datetime as dt + +def search_days(start, stop): + + day = (start + dt.timedelta(x) for x in range((stop - start).days + 1)) + work_day = sum(1 for day in day if day.weekday() < 5) + print(work_day) + +start_day = dt.date(2020,1,1) +stop_day = dt.date(2020,2,1) + +search_days(start_day, stop_day) + + + + + diff --git a/Practice/GrishchenkoA/9.3.py b/Practice/GrishchenkoA/9.3.py new file mode 100644 index 0000000..e69de29 diff --git a/Practice/GrishchenkoA/9.4.2.py b/Practice/GrishchenkoA/9.4.2.py new file mode 100644 index 0000000..e69de29 diff --git a/Practice/GrishchenkoA/9.4.py b/Practice/GrishchenkoA/9.4.py new file mode 100644 index 0000000..e69de29 diff --git a/Practice/GrishchenkoA/exam.py b/Practice/GrishchenkoA/exam.py new file mode 100644 index 0000000..e69de29 diff --git a/Practice/GrishchenkoA/first.py b/Practice/GrishchenkoA/first.py new file mode 100644 index 0000000..c07a133 --- /dev/null +++ b/Practice/GrishchenkoA/first.py @@ -0,0 +1,2 @@ +city = input("Введите город: ") +print(f"Echo: {city}") \ No newline at end of file diff --git a/Practice/GrishchenkoA/task 2.py b/Practice/GrishchenkoA/task 2.py new file mode 100644 index 0000000..e69de29