From 3353e57f9336791cde3872fcff658770ec28e3ce Mon Sep 17 00:00:00 2001 From: Artem Prigodsky Date: Sat, 2 Jan 2021 12:38:37 +0800 Subject: [PATCH] lession7 --- task1.py | 34 ++++++++++++++++++++++++++++++++++ task2.py | 23 +++++++++++++++++++++++ task3.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+) create mode 100644 task1.py create mode 100644 task2.py create mode 100644 task3.py diff --git a/task1.py b/task1.py new file mode 100644 index 0000000..225d99f --- /dev/null +++ b/task1.py @@ -0,0 +1,34 @@ +class Matrix: + matrix = {} + + def __init__(self, matrix): + self.matrix = matrix + + def __str__(self): + res = '' + for row in self.matrix: + for cell in row: + res += f"{cell} " + res += "\n" + return res + + def __add__(self, other): + for i_row, row in enumerate(other): + for i_cell, cell in enumerate(row): + self.matrix[i_row][i_cell] += cell + + +test_matrix = [ + [23, 50, 100], + [54, 12, 2], + [56, 77, 45] +] +test_matrix2 = [ + [23, 50, 100], + [54, 12, 2], + [56, 77, 45] +] + +mc = Matrix(test_matrix) +plus = mc + test_matrix2 +print(mc) diff --git a/task2.py b/task2.py new file mode 100644 index 0000000..6cc33e0 --- /dev/null +++ b/task2.py @@ -0,0 +1,23 @@ +class Cloth: + # type_cloth = 'costume' + type_cloth = 'coat' + size = 0 + + def __init__(self, type_cloth): + self.type_cloth = type_cloth + + def set_size(self, size): + self.size = size + + @property + def textile(self): + if self.type_cloth == 'coat': + res = self.size / 6.5 + 0.5 + else: + res = 2 * self.size + 0.3 + return res + + +cloth = Cloth('coat') +cloth.set_size(500) +print(cloth.textile) diff --git a/task3.py b/task3.py new file mode 100644 index 0000000..c8a9c7f --- /dev/null +++ b/task3.py @@ -0,0 +1,44 @@ +class Cell: + count_cells = 0 + + def __init__(self, count_cells): + self.count_cells = count_cells + + def __add__(self, other): + self.count_cells += other.count_cells + return self + + def __sub__(self, other): + res = self.count_cells - other.count_cells + if res > 0: + self.count_cells = res + return self + else: + print("Ошибка вычитания клеток!") + + def __mul__(self, other): + res = self.count_cells * other.count_cells + return Cell(res) + + def __truediv__(self, other): + res = self.count_cells // other.count_cells + return Cell(res) + + def make_order(self, cells_in_row): + res = "" + cc = self.count_cells + while cc > 0: + cir = cells_in_row + while cir > 0 and cc > 0: + res += "*" + cir -= 1 + cc -= 1 + res += "\n" + return res + + +cell_1 = Cell(50) +cell_2 = Cell(45) + +order = cell_1.make_order(13) +print(order)