From 0a31eeba643f99aef9199468cc0a15bb230ede0a Mon Sep 17 00:00:00 2001 From: getblad Date: Sat, 19 Sep 2020 15:39:13 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=97=20=D0=BA=207=20=D1=83=D1=80=D0=BE?= =?UTF-8?q?=D0=BA=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- #1.py | 21 +++++++++++++++++++++ #2.py | 29 +++++++++++++++++++++++++++++ #3.py | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+) create mode 100644 #1.py create mode 100644 #2.py create mode 100644 #3.py diff --git a/#1.py b/#1.py new file mode 100644 index 0000000..5b9a8ca --- /dev/null +++ b/#1.py @@ -0,0 +1,21 @@ +class Matrix: + def __init__(self, matrix_list): + self.matrix = matrix_list + + def __str__(self): + for list in self.matrix: + for number in list: + print(number, end=' ') + print() + return '' + + def __add__(self, other): + return Matrix([[i+n for i, n in zip(a, b)] for a, b in zip(self.matrix, other.matrix)]) + + +matrix = [[1, 2, 3, 5], [1, 2, 3, 4], [1, 2, 2, 7]] +matrix2 = [[1, 2, 3, 5], [1, 2, 3, 4], [1, 2, 2, 7]] +ma = Matrix(matrix) +ma2 = Matrix(matrix2) +c = ma + ma2 +print(c) diff --git a/#2.py b/#2.py new file mode 100644 index 0000000..803de43 --- /dev/null +++ b/#2.py @@ -0,0 +1,29 @@ +class Clothes: + def __init__(self, name): + self.name = name + + +class Costume(Clothes): + def __init__(self, name, height): + super().__init__(name) + self.height = height + + @property + def consumption(self): + return f'Расход ткани на {self.name} составит {2 * self.height + 3}' + + +class Coat(Clothes): + def __init__(self, name, size): + super().__init__(name) + self.size = size + + @property + def consumption(self): + return f'Расход ткани на {self.name} составит {self.size / 6.5 + 0.5:.2f}' + + +My_costume = Costume('ASD', 29) +My_coat = Coat('Wary', 30) +print(My_costume.consumption) +print(My_coat.consumption) diff --git a/#3.py b/#3.py new file mode 100644 index 0000000..54e301f --- /dev/null +++ b/#3.py @@ -0,0 +1,54 @@ +class Cell: + + def __init__(self, quantity): + self.quantity = quantity + + def __add__(self, other): + return Cell(self.quantity + other.quantity) + + def __sub__(self, other): + sub = self.quantity - other.quantity + if sub > 0: + return Cell(sub) + else: + print(f'Из клетки {self.get_name()} невозможно вычесть {other.get_name()}', end='') + return '' + + def __mul__(self, other): + return Cell(self.quantity * other.quantity) + + def __truediv__(self, other): + return Cell(self.quantity // other.quantity) + + def __str__(self): + return str(self.quantity) + + def get_name(self): + for k, v in globals().items(): + if v is self: + return k + + def make_order(self, row): + a = '' + if row > self.quantity: + return f'{"*" * self.quantity}' + n = 0 + for i in range(self.quantity//row + 1): + if self.quantity - n < row: + a = ''.join([a, f'{"*" * (self.quantity - n)}\n']) + return a + a = ''.join([a, f'{"*" * row}\n']) + n += row + return a + + +x = Cell(3) +y = Cell(11) + +print(y - x) +print(x - y) +print(x*y) +print(x+y) +print(x/y) +print(y/x) +print(y.make_order(2))