From f580e31c1245b5588c7e4ccb73afc0abf6886347 Mon Sep 17 00:00:00 2001 From: "d.zashivalov" Date: Mon, 25 Apr 2022 17:48:52 +0300 Subject: [PATCH] Lesson_8 --- lesson_8/8-1.py | 38 +++++++++++++++++++++++++++++ lesson_8/8-2.py | 17 +++++++++++++ lesson_8/8-3.py | 28 +++++++++++++++++++++ lesson_8/8-4-5-6.py | 59 +++++++++++++++++++++++++++++++++++++++++++++ lesson_8/8-7.py | 23 ++++++++++++++++++ 5 files changed, 165 insertions(+) create mode 100644 lesson_8/8-1.py create mode 100644 lesson_8/8-2.py create mode 100644 lesson_8/8-3.py create mode 100644 lesson_8/8-4-5-6.py create mode 100644 lesson_8/8-7.py diff --git a/lesson_8/8-1.py b/lesson_8/8-1.py new file mode 100644 index 0000000..d99b47f --- /dev/null +++ b/lesson_8/8-1.py @@ -0,0 +1,38 @@ +class Data: + def __init__(self, day_month_year): + self.day_month_year = str(day_month_year) + + @classmethod + def extract(cls, day_month_year): + my_date = [] + + for i in day_month_year.split(): + if i != '-': my_date.append(i) + + return int(my_date[0]), int(my_date[1]), int(my_date[2]) + + @staticmethod + def valid(day, month, year): + + if 1 <= day <= 31: + if 1 <= month <= 12: + if 2019 >= year >= 0: + return f'All right' + else: + return f'Неправильный год' + else: + return f'Неправильный месяц' + else: + return f'Неправильный день' + + def __str__(self): + return f'Текущая дата {Data.extract(self.day_month_year)}' + + +today = Data('11 - 1 - 2001') +print(today) +print(Data.valid(11, 11, 2022)) +print(today.valid(11, 13, 2011)) +print(Data.extract('11 - 11 - 2011')) +print(today.extract('11 - 11 - 2020')) +print(Data.valid(1, 11, 2000)) diff --git a/lesson_8/8-2.py b/lesson_8/8-2.py new file mode 100644 index 0000000..90003f7 --- /dev/null +++ b/lesson_8/8-2.py @@ -0,0 +1,17 @@ +class DivisionByNull: + def __init__(self, divider, denominator): + self.divider = divider + self.denominator = denominator + + @staticmethod + def divide_by_null(divider, denominator): + try: + return (divider / denominator) + except: + return (f"Деление на ноль недопустимо") + + +div = DivisionByNull(10, 100) +print(DivisionByNull.divide_by_null(10, 0)) +print(DivisionByNull.divide_by_null(10, 0.1)) +print(div.divide_by_null(100, 0)) \ No newline at end of file diff --git a/lesson_8/8-3.py b/lesson_8/8-3.py new file mode 100644 index 0000000..cef7528 --- /dev/null +++ b/lesson_8/8-3.py @@ -0,0 +1,28 @@ +class Error: + def __init__(self, *args): + self.my_list = [] + + def my_input(self): + + # self.my_list = [int(i) for i in input('Введите значения через пробел ').split()] + # val = int(input('Введите значения и нажимайте Enter - ')) + # self.my_list.append(val) + while True: + try: + val = int(input('Введите значения и нажимайте Enter - ')) + self.my_list.append(val) + print(f'Текущий список - {self.my_list} \n ') + except: + print(f"Недопустимое значение") + y_or_n = input(f'Попробовать еще раз? Y/N ') + + if y_or_n == 'Y' or y_or_n == 'y': + print(try_except.my_input()) + elif y_or_n == 'N' or y_or_n == 'n': + return f'Вы вышли' + else: + return f'Вы вышли' + + +try_except = Error(1) +print(try_except.my_input()) diff --git a/lesson_8/8-4-5-6.py b/lesson_8/8-4-5-6.py new file mode 100644 index 0000000..2e16f2b --- /dev/null +++ b/lesson_8/8-4-5-6.py @@ -0,0 +1,59 @@ +class StoreMashines: + + def __init__(self, name, price, quantity, number_of_lists, *args): + self.name = name + self.price = price + self.quantity = quantity + self.numb = number_of_lists + self.my_store_full = [] + self.my_store = [] + self.my_unit = {'Модель устройства': self.name, 'Цена за ед': self.price, 'Количество': self.quantity} + + def __str__(self): + return f'{self.name} цена {self.price} количество {self.quantity}' + + def reception(self): + try: + unit = input(f'Введите наименование ') + unit_p = int(input(f'Введите цену за ед ')) + unit_q = int(input(f'Введите количество ')) + unique = {'Модель устройства': unit, 'Цена за ед': unit_p, 'Количество': unit_q} + self.my_unit.update(unique) + self.my_store.append(self.my_unit) + print(f'Текущий список -\n {self.my_store}') + except: + return f'Ошибка ввода данных' + + print(f'Для выхода - Q, продолжение - Enter') + q = input(f'---> ') + if q == 'Q' or q == 'q': + self.my_store_full.append(self.my_store) + print(f'Весь склад -\n {self.my_store_full}') + return f'Выход' + else: + return StoreMashines.reception(self) + + +class Printer(StoreMashines): + def to_print(self): + return f'to print smth {self.numb} times' + + +class Scanner(StoreMashines): + def to_scan(self): + return f'to scan smth {self.numb} times' + + +class Copier(StoreMashines): + def to_copier(self): + return f'to copier smth {self.numb} times' + + +unit_1 = Printer('hp', 2000, 5, 10) +unit_2 = Scanner('Canon', 1200, 5, 10) +unit_3 = Copier('Xerox', 1500, 1, 15) +print(unit_1.reception()) +print(unit_2.reception()) +print(unit_3.reception()) +print(unit_1.to_print()) +print(unit_3.to_copier()) \ No newline at end of file diff --git a/lesson_8/8-7.py b/lesson_8/8-7.py new file mode 100644 index 0000000..102565b --- /dev/null +++ b/lesson_8/8-7.py @@ -0,0 +1,23 @@ +class ComplexNumber: + def __init__(self, a, b, *args): + self.a = a + self.b = b + self.z = 'a + b * i' + + def __add__(self, other): + print(f'Сумма z1 и z2 равна') + return f'z = {self.a + other.a} + {self.b + other.b} * i' + + def __mul__(self, other): + print(f'Произведение z1 и z2 равно') + return f'z = {self.a * other.a - (self.b * other.b)} + {self.b * other.a} * i' + + def __str__(self): + return f'z = {self.a} + {self.b} * i' + + +z_1 = ComplexNumber(1, -2) +z_2 = ComplexNumber(3, 4) +print(z_1) +print(z_1 + z_2) +print(z_1 * z_2) \ No newline at end of file