From 25bc9277054820eeaddb1e6549d8bdab52290f2d Mon Sep 17 00:00:00 2001 From: "d.zashivalov" Date: Sat, 23 Apr 2022 19:08:32 +0300 Subject: [PATCH] Lesson_7 --- lesson_7/7-1.py | 30 ++++++++++++++++++++++++++++++ lesson_7/7-2.py | 43 +++++++++++++++++++++++++++++++++++++++++++ lesson_7/7-3.py | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 lesson_7/7-1.py create mode 100644 lesson_7/7-2.py create mode 100644 lesson_7/7-3.py diff --git a/lesson_7/7-1.py b/lesson_7/7-1.py new file mode 100644 index 0000000..89c793e --- /dev/null +++ b/lesson_7/7-1.py @@ -0,0 +1,30 @@ +class Matrix: + def __init__(self, list_1, list_2): + self.list_1 = list_1 + self.list_2 = list_2 + + def __add__(self): + matr = [[0, 0, 0], + [0, 0, 0], + [0, 0, 0]] + + for i in range(len(self.list_1)): + + for j in range(len(self.list_2[i])): + matr[i][j] = self.list_1[i][j] + self.list_2[i][j] + + return str('\n'.join(['\t'.join([str(j) for j in i]) for i in matr])) + + def __str__(self): + return str('\n'.join(['\t'.join([str(j) for j in i]) for i in matr])) + + +my_matrix = Matrix([[5, 18, 11], + [6, 17, 23], + [41, 50, 9]], + [[45, 8, 2], + [6, 7, 93], + [24, 5, 97]]) + + +print(my_matrix.__add__()) \ No newline at end of file diff --git a/lesson_7/7-2.py b/lesson_7/7-2.py new file mode 100644 index 0000000..88c55cb --- /dev/null +++ b/lesson_7/7-2.py @@ -0,0 +1,43 @@ +class Textil: + def __init__(self, width, height): + self.width = width + self.height = height + + def get_square_c(self): + return self.width / 6.5 + 0.5 + + def get_square_j(self): + return self.height * 2 + 0.3 + + @property + def get_sq_full(self): + return str(f'Площадь общая ткани \n' + f' {(self.width / 6.5 + 0.5) + (self.height * 2 + 0.3)}') + + +class Coat(Textil): + def __init__(self, width, height): + super().__init__(width, height) + self.square_c = round(self.width / 6.5 + 0.5) + + def __str__(self): + return f'Площадь на пальто {self.square_c}' + + +class Jacket(Textil): + def __init__(self, width, height): + super().__init__(width, height) + self.square_j = round(self.height * 2 + 0.3) + + def __str__(self): + return f'Площадь на костюм {self.square_j}' + + +coat = Coat(2, 4) +jacket = Jacket(1, 2) +print(coat) +print(jacket) +print(coat.get_sq_full) +print(jacket.get_sq_full) +print(jacket.get_square_c()) +print(jacket.get_square_j()) \ No newline at end of file diff --git a/lesson_7/7-3.py b/lesson_7/7-3.py new file mode 100644 index 0000000..3d3afa6 --- /dev/null +++ b/lesson_7/7-3.py @@ -0,0 +1,41 @@ +class Cell: + def __init__(self, quantity): + self.quantity = int(quantity) + # self.result = result + + def __str__(self): + return f'Результат операции {self.quantity * "*"}' + + def __add__(self, other): + # self.result = Cell(self.quantity + other.quantity) + return Cell(self.quantity + other.quantity) + + def __sub__(self, other): + return self.quantity - other.quantity if (self.quantity - other.quantity) > 0 else print('Отрицательно!') + + # return Cell(int(self.quantity - other.quantity)) + + def __mul__(self, other): + # self.result = Cell(int(self.quantity * other.quantity)) + return Cell(int(self.quantity * other.quantity)) + + def __truediv__(self, other): + # self.result = Cell(round(self.quantity // other.quantity)) + return Cell(round(self.quantity // other.quantity)) + + def make_order(self, cells_in_row): + row = '' + for i in range(int(self.quantity / cells_in_row)): + row += f'{"*" * cells_in_row} \\n' + row += f'{"*" * (self.quantity % cells_in_row)}' + return row + + +cells1 = Cell(33) +cells2 = Cell(9) +print(cells1) +print(cells1 + cells2) +print(cells2 - cells1) +print(cells2.make_order(5)) +print(cells1.make_order(10)) +print(cells1 / cells2) \ No newline at end of file