diff --git a/lab_1_task_1.py b/lab_1_task_1.py new file mode 100644 index 0000000..b1987d4 --- /dev/null +++ b/lab_1_task_1.py @@ -0,0 +1,33 @@ +class SchoolDiary: + def __init__(self, subject, student, grade_list): + self.subject = subject + self.student = student + self.grade_list = grade_list + + def grade(self, num): + if num < 1 or num > 5: + return "Недопустимое число! \nПожалуйста, введите число от 1 до 5." + return self.grade_list.append(num) + + def final_grade(self): + sum_grade = sum(self.grade_list) + + res = sum_grade / len(self.grade_list) + print(f"Окончательная оценка: {res}") + + + def printer(self): + print(f"Ученик: {self.student}") + print(f"Предмет: {self.subject}") + print(f"Оценки: {self.grade_list}") + + +if __name__ == '__main__': + obj = SchoolDiary("Информатика", "Иванов Иван", [4, 5, 5, 4, 5]) + + obj.grade(3) + + obj.printer() + obj.final_grade() + + \ No newline at end of file diff --git a/lab_1_task_2.py b/lab_1_task_2.py new file mode 100644 index 0000000..d8f7f54 --- /dev/null +++ b/lab_1_task_2.py @@ -0,0 +1,94 @@ +class Pyramid: + def __init__(self, max_h): + self.max_h = max_h + self.bricks_count = 0 + self.total_h = 0 + self.bricks_in_current_row = 0 + + self.bricks_rows = [i for i in range(self.max_h, 0, -1)] + self.all_bricks = sum(self.bricks_rows) + print(self.all_bricks) + + def add_bricks(self, num): + self.bricks_count += num + while self.total_h < self.max_h: + bricks_in_rows = self.bricks_rows[self.total_h] + if self.bricks_in_current_row + num >= bricks_in_rows: + num -= (bricks_in_rows - self.bricks_in_current_row) + self.bricks_in_current_row = 0 + self.total_h += 1 + else: + self.bricks_in_current_row += num + break + + if num > 0 and self.total_h < self.max_h: + self.bricks_in_current_row += num + + if self.total_h >= self.max_h: + print('Пирамида достигла максимальной высоты!') + + + + def get_height(self): + # Выводим текущую высоту пирамиды + + print(f"Высота пирамиды: {self.total_h}.") + + + def is_done(self): + res_bricks = self.bricks_count / self.all_bricks * 100 + return res_bricks + + +class Builder: + def __init__(self, bricks): + self.bricks = bricks + self.day = 1 + self.my_pyramid = Pyramid(15) + + def buy_bricks(self): + self.bricks += 5 + print(f"Куплено 5 кирпичей. Теперь у строителя {self.bricks} кирпичей.") + + def build_pyramid(self, n): + if self.bricks >= n: + self.bricks -= n + return n + else: + print("Недостаточно кирпичей!") + return 0 + + def work_day(self): + needed_bricks = min(5, self.bricks + 5) + added_bricks = self.build_pyramid(needed_bricks) + + + if added_bricks > 0: + self.my_pyramid.add_bricks(added_bricks) + + print(f"День {self.day}.") + print(f"Строили пирамиду: добавлено {added_bricks} кирпичей.") + print(f"Остаток кирпичей у строителя: {self.bricks}.") + self.my_pyramid.get_height() # Выводим текущую высоту пирамиды + + + readiness = self.my_pyramid.is_done() + print(f"Готовность пирамиды: {readiness:.2f}%.") + + + if readiness >= 100: + print("Пирамида завершена!") + exit(0) + + + if added_bricks == 0: + self.buy_bricks() + + self.day += 1 + +if __name__ == '__main__': + b = Builder(13) + + while True: + b.work_day() + \ No newline at end of file diff --git a/lab_1_task_3.py b/lab_1_task_3.py new file mode 100644 index 0000000..797cf60 --- /dev/null +++ b/lab_1_task_3.py @@ -0,0 +1,81 @@ +class Puppy: + states = ["Болеет", "Выздоравливает", "Здоров"] + + def __init__(self, index): + self.index = index + self.state = self.states[0] + + def get_treatment(self): + if self.state == self.states[0]: + self.state = self.states[1] + elif self.state == self.states[1]: + self.state = self.states[2] + else: + return 0 + + def is_healthy(self): + if self.state == self.states[2]: + return "Щенок здоров" + + +class Dog: + def __init__(self, puppy_count): + self.puppies = [Puppy(i) for i in range(1, puppy_count + 1)] + + def health_all(self): + for puppy in self.puppies: + puppy.get_treatment() + + def all_are_healthy(self): + for puppy in self.puppies: + if puppy.is_healthy(): + continue + else: + return False + return True + + def give_away_all(self): + if self.all_are_healthy(): + self.puppies.clear() + print("Все щенки присроены в хорошие руки") + else: + print("Не все щенки здоровы") + + +class Vet: + def __init__(self, name, dog): + self.name = name + self.dog = dog + + def work(self): + self.dog.health_all() + print(f"Все щенки получили лечение от {self.name}") + def care(self): + if self.dog.all_are_healthy(): + print("Все щенки здоровы") + self.dog.give_away_all() + else: + print("Есть нездоровые щенки") + + def knowledge_base(self): + print("База знаний ветеринарской клиники") + print("1. Проводить регулярные осмотры щенков") + print("2. Провести лечение нездоровых щенков") + print("3. Выдать доказательства здоровья") + print("4. Пристроить щенков в хорошие руки") + + +if __name__ == '__main__': + + dog = Dog(puppy_count=5) + + vet = Vet("Иванов Иван", dog) + + vet.knowledge_base() + vet.work() + vet.care() + dog.give_away_all() + vet.work() + vet.care() + + diff --git a/lab_1_task_4.py b/lab_1_task_4.py new file mode 100644 index 0000000..276b05e --- /dev/null +++ b/lab_1_task_4.py @@ -0,0 +1,49 @@ +import random + +class Supplier: + + def __init__(self, name, location): + self.name = name + self.location = location + self.products = ['BTC', 'ETH', 'TETHER_USDT'] + + def add_product(self, product): + self.products.append(product) + + def get_info(self): + return f'Supplier Name: {self.name}, Location: {self.location}, Products: {self.products}' + +class Customer: + + def __init__(self, name, address): + self.name = name + self.address = address + self.orders = [] + + def buy_order(self, order): + self.orders.append(order) + + def get_info(self): + return f'Customer Name: {self.name}, Address: {self.address}, Orders: {self.orders}' + +class VPN: + def __init__(self): + self.suppliers_info = [] + self.customers_info = [] + + def hide(self): + address = ['RUSSIA, MOSCOW', 'FRANCE, PARIS', 'USA, Los Angeles'] + return random.choice(address) + def get_location(self): + print("ДАННЫХ НЕ НАЙДЕНО!") + + +if __name__ == "__main__": + vpn = VPN() + supplier1 = Supplier('Supplier ER', location=vpn.hide()) + customer = Customer('Supplier KTX', address='Moscow, Moscow City, tower 1') + customer.buy_order(supplier1.products[2]) + + print(supplier1.get_info()) + print(customer.get_info()) + diff --git a/lab_2_task2.py b/lab_2_task2.py new file mode 100644 index 0000000..7d7272a --- /dev/null +++ b/lab_2_task2.py @@ -0,0 +1,22 @@ + +def operation_decorator(func): + def wrapper(x, y, operation): + if operation == '+': + return func(x, y, lambda x, y: x + y) + elif operation == '-': + return func(x, y, lambda x, y: x - y) + elif operation == '*': + return func(x, y, lambda x, y: x * y) + elif operation == '/': + if y != 0: + return func(x, y, lambda x, y: x / y) + else: + return "Error: Division by zero" + return wrapper + +@operation_decorator +def calculate(x, y, operation_func): + return operation_func(x, y) + +result = calculate(5, 3, '+') +print(result) diff --git a/lab_2_task3.py b/lab_2_task3.py new file mode 100644 index 0000000..49ddee0 --- /dev/null +++ b/lab_2_task3.py @@ -0,0 +1,20 @@ + + +import math +def debug(func): + def wrapper(*args, **kwargs): + print(f"Calling {func.__name__} with arguments {args}") + + result = func(*args, **kwargs) + + print(f'{func.__name__} returned: {result}') + + return result + + return wrapper + +@debug +def sq(x, y): + return math.sqrt(x * y) + +result = sq(3, 3) diff --git a/lab_2_task4.py b/lab_2_task4.py new file mode 100644 index 0000000..2b5dff6 --- /dev/null +++ b/lab_2_task4.py @@ -0,0 +1,29 @@ + + +class Planet: + def __init__(self): + self.radius = 12.3 + + self._mask = 2 + + @classmethod + def get_radius(self, cls): + return cls.radius + + + @property + def mask(self): + return self._mask + + + @staticmethod + def _print_info(self): + print(f"Planet radius: {self.radius}") + print(f"Planet mask: {self._mask}") + + + +r = Planet() +print(r.get_radius(cls=r)) +print(r.mask) +print(r._print_info(r)) diff --git a/lab_2_task_1.py b/lab_2_task_1.py new file mode 100644 index 0000000..00ef9ca --- /dev/null +++ b/lab_2_task_1.py @@ -0,0 +1,15 @@ +def wrapper_function(num): + def ad(func): + def sum_of_two_num(num1): + print(num + num1) + return func() + return sum_of_two_num + return ad + +@wrapper_function(1) +def send_num(): + print("Sending") + + +send_num(3) + diff --git a/lec_1_dynamic_fields.py b/lec_1_dynamic_fields.py new file mode 100644 index 0000000..09ee50a --- /dev/null +++ b/lec_1_dynamic_fields.py @@ -0,0 +1,17 @@ +import random + +class Ball: + def __init__(self, mass): + self.mass = mass + self.image = "NMX" + + def get_random_model(self): + cj = ['Nike', 'Adidas', 'Reebok', 'Puma', 'Converse'] + + res = random.choice(cj) + return res + +ball = Ball(10) + +print(ball.mass, ball.image) +print(ball.get_random_model()) \ No newline at end of file diff --git a/lec_1_static_fields.py b/lec_1_static_fields.py new file mode 100644 index 0000000..282e459 --- /dev/null +++ b/lec_1_static_fields.py @@ -0,0 +1,9 @@ + + +class Ball: + pass + + + +print(dir(Ball)) + diff --git a/lec_1_user_fields.py b/lec_1_user_fields.py new file mode 100644 index 0000000..86dd580 --- /dev/null +++ b/lec_1_user_fields.py @@ -0,0 +1,33 @@ +import random + +class Ball: + def __init__(self, mass): + self.mass = mass + self.image = "NMX" + self.x, self.y = 0, 0 + + def get_random_model(self): + cj = ['Nike', 'Adidas', 'Reebok', 'Puma', 'Converse'] + + res = random.choice(cj) + return res + + def get_random_num(self, max_length): + return random.randint(1, max_length) + + def drop(self): + self.y += 1 + return 'Я подбросился на', self.y + def kick(self): + self.x += 1 + return "Меня пнули на ", self.x + +ball = Ball(10) + +print(ball.mass, ball.image) +print(ball.get_random_model()) + +print(ball.get_random_num(max_length=100)) +for _ in range(10): + print(ball.drop(), ball.y) + print(ball.x, ball.y) diff --git a/less_1.py b/less_1.py new file mode 100644 index 0000000..e69de29