diff --git a/1.py b/1.py new file mode 100644 index 0000000..a07f58e --- /dev/null +++ b/1.py @@ -0,0 +1,36 @@ + +class Matrix(): + def __init__(self, in_li_lists): + self.main_li = in_li_lists + + def __str__(self): + res = '' + for i in self.main_li: + res += '\n' + for j in i: + res += f"{j} " + return res + + +class Matrix2(Matrix): + + def __add__(self, new): + new_matrix = [] + for num_i, i in enumerate(self.main_li): + inner_li = [] + for num_j, j in enumerate(i): + inner_li.append(j+new.main_li[num_i][num_j]) + new_matrix.append(inner_li) + + return Matrix(new_matrix) + + +li_lists = [[1, 2, 3, 4, 5], [2, 5, 76, 72]] +mx = Matrix(li_lists) +# print(mx) # test __str__ + + +mx1 = Matrix2([[1, 2, 3, 4, 5], [2, 5, 76, 72]]) +mx2 = Matrix2([[1, 1, 1, 1, 1], [1, 1, 1, 1]]) +mx3 = mx1 + mx2 +print(mx3) # test __add__ diff --git a/2.py b/2.py new file mode 100644 index 0000000..1490ca5 --- /dev/null +++ b/2.py @@ -0,0 +1,53 @@ +from abc import abstractmethod + +class Clothes(): + def __init__(self, name, param): + self.name = name + self.param = param + + def __str__(self): + return f'{self.name} size {self.param}' + + @abstractmethod + def rate_textile(self): + self.all_textile = 2*self.param + 0.3 + return self.all_textile + + def __add__(self, Clothes): + return self.all_textile + Clothes.all_textile + + + +class Coat(Clothes): + # def __init__(self, name, param): + # super().__init__(f' zzzz {name}', param) + # Clothes.name = f' zzzz {name}' + # Clothes.param = param + @property + def rate_textile(self): + self.all_textile = self.param/6.5 + 0.5 + return self.all_textile + + + + +class Suit(Clothes): + @property + def rate_textile(self): + self.all_textile = 2*self.param + 0.3 + return self.all_textile + + + + + + + + +co = Coat('пальто', 44) +su = Suit('костюм', 42) +print(co.rate_textile) # test property +print(su.rate_textile) # test property + +all = co + su +print(all) diff --git a/3.py b/3.py new file mode 100644 index 0000000..6a27c60 --- /dev/null +++ b/3.py @@ -0,0 +1,46 @@ +class Cage(): + def __init__(self, quantity): + self.quantity = quantity + + def __str__(self): + return f'{Cage} quantity - {self.quantity}' + + def __add__(self, new): + new_quantity = self.quantity + new.quantity + return Cage(new_quantity) + + def __sub__(self, new): + res = self.quantity - new.quantity + if res > 0: + return res + else: + print('error pirnt!!!!!!!!') + + def __mul__(self, new): + new_quantity = self.quantity * new.quantity + return Cage(new_quantity) + + def __truediv__(self, new): + new_quantity = int(self.quantity / new.quantity) + return Cage(new_quantity) + + def make_order(self, value): + count = 0 + res = '' + for i in range(self.quantity): + res += '*' + count += 1 + if count == value: + res += '\n' + count = 0 + return res + + +c1 = Cage(10) +c2 = Cage(2) + +c3 = c1 / c2 +# print(c3) +c4 = Cage(20) +res = c4.make_order(5) +print(res)