From b54921764eb2cf6caf7eafed0f55e7f068ce21a2 Mon Sep 17 00:00:00 2001
From: Pavel
Date: Tue, 29 Mar 2022 16:34:05 +0300
Subject: [PATCH 01/11] The first variant. There are some problems.
---
Lesson_7/task_1.py | 51 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 51 insertions(+)
create mode 100644 Lesson_7/task_1.py
diff --git a/Lesson_7/task_1.py b/Lesson_7/task_1.py
new file mode 100644
index 0000000..76d133f
--- /dev/null
+++ b/Lesson_7/task_1.py
@@ -0,0 +1,51 @@
+# Реализовать класс Matrix (матрица). Обеспечить перегрузку конструктора класса (метод __init__()),
+# который должен принимать данные (список списков) для формирования матрицы.
+# Подсказка: матрица — система некоторых математических величин, расположенных в виде прямоугольной схемы.
+# Примеры матриц: 3 на 2, 3 на 3, 2 на 4.
+#
+# 31 32 3 5 32 3 5 8 3
+# 37 43 2 4 6 8 3 7 1
+# 51 86 -1 64 -8
+# Следующий шаг — реализовать перегрузку метода __str__() для вывода матрицы в привычном виде.
+# Далее реализовать перегрузку метода __add__() для реализации операции сложения двух объектов класса
+# Matrix (двух матриц). Результатом сложения должна быть новая матрица. Подсказка: сложение элементов матриц
+# выполнять поэлементно — первый элемент первой строки первой матрицы складываем
+# с первым элементом первой строки второй матрицы и т.д.
+
+class Matrix:
+ def __init__(self, MyMatrix_1, MyMatrix_2, result):
+ self.MyMatrix_1 = MyMatrix_1
+ self.MyMatrix_2 = MyMatrix_2
+ self.result = result
+
+ def __add__(self, MyMatrix_1, MyMatrix_2, result):
+ self.result = []
+ self.MyMatrix_1 = []
+ for i in range(n):
+ row = input().split()
+ for i in range(len(row)):
+ row[i] = int(row[i])
+ self.MyMatrix_1.append(row)
+
+ self.MyMatrix_2 = []
+ for i in range(m):
+ row = input().split()
+ for i in range(len(row)):
+ row[i] = int(row[i])
+ self.MyMatrix_2.append(row)
+
+ self.result = [[MyMatrix_1[i][j] + MyMatrix_2[i][j] for j in range(len(MyMatrix_1[0]))] for i in
+ range(len(MyMatrix_1))]
+
+ def __str__(self):
+ pass
+ # result = [[MyMatrix_1[i][j] + MyMatrix_2[i][j] for j in range(len(MyMatrix_1[0]))] for i in range(len(MyMatrix_1))]
+
+
+result = n = int(input('Enter a number of row for MyMatrix_1: '))
+m = int(input('Enter a number of row for MyMatrix_2: '))
+
+print(result.__add__)
+
+# for r in result:
+# print(r)
From 3290477531fb8385374fcd9403cd9c63b9f7d88f Mon Sep 17 00:00:00 2001
From: Pavel
Date: Tue, 29 Mar 2022 21:56:26 +0300
Subject: [PATCH 02/11] Still in progress...
---
Lesson_7/task_1.py | 48 +++++++++++++++++++++++++++++-----------------
1 file changed, 30 insertions(+), 18 deletions(-)
diff --git a/Lesson_7/task_1.py b/Lesson_7/task_1.py
index 76d133f..64d0d5d 100644
--- a/Lesson_7/task_1.py
+++ b/Lesson_7/task_1.py
@@ -13,39 +13,51 @@
# с первым элементом первой строки второй матрицы и т.д.
class Matrix:
+
def __init__(self, MyMatrix_1, MyMatrix_2, result):
self.MyMatrix_1 = MyMatrix_1
self.MyMatrix_2 = MyMatrix_2
self.result = result
- def __add__(self, MyMatrix_1, MyMatrix_2, result):
- self.result = []
+ def __add__(self):
+
+ result = [[0] * M for i in range(N)]
+
self.MyMatrix_1 = []
- for i in range(n):
+ for i in range(N):
row = input().split()
for i in range(len(row)):
row[i] = int(row[i])
self.MyMatrix_1.append(row)
- self.MyMatrix_2 = []
- for i in range(m):
- row = input().split()
- for i in range(len(row)):
- row[i] = int(row[i])
- self.MyMatrix_2.append(row)
+ self.MyMatrix_2 = []
+ for i in range(M):
+ row = input().split()
+ for i in range(len(row)):
+ row[i] = int(row[i])
+ self.MyMatrix_2.append(row)
+
+ for i in range(len(self.MyMatrix_1)):
- self.result = [[MyMatrix_1[i][j] + MyMatrix_2[i][j] for j in range(len(MyMatrix_1[0]))] for i in
- range(len(MyMatrix_1))]
+ for j in range(len(self.MyMatrix_2[i])):
+ result[i][j] = self.MyMatrix_1[i][j] + self.MyMatrix_2[i][j]
+
+ return str('\n'.join(['\t'.join([str(j) for j in i]) for i in result]))
def __str__(self):
- pass
- # result = [[MyMatrix_1[i][j] + MyMatrix_2[i][j] for j in range(len(MyMatrix_1[0]))] for i in range(len(MyMatrix_1))]
+ return str('\n'.join(['\t'.join([str(j) for j in i]) for i in result]))
+
+N = int(input('N = '))
+M = int(input('M = '))
-result = n = int(input('Enter a number of row for MyMatrix_1: '))
-m = int(input('Enter a number of row for MyMatrix_2: '))
+# empty_matr = (matr.__add__())
+# n = int(input('Enter a number n: '))
+# total = (self.MyMatrix_1([]))
+# print(total.MyMatrix_1)
+# m = int(input('Enter a number m: '))
+my_matrix = Matrix([])
+# result = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
-print(result.__add__)
-# for r in result:
-# print(r)
+print(my_matrix.__add__())
From d9d93025e59b3a9dd356895abb5f941cc91cd0d4 Mon Sep 17 00:00:00 2001
From: Pavel
Date: Tue, 29 Mar 2022 22:31:04 +0300
Subject: [PATCH 03/11] still unable to enter matrix data from the keyboard. I
can't understand what is wrong.
---
Lesson_7/task_1.py | 46 ++++++++++++++++++++++------------------------
1 file changed, 22 insertions(+), 24 deletions(-)
diff --git a/Lesson_7/task_1.py b/Lesson_7/task_1.py
index 64d0d5d..bcb9340 100644
--- a/Lesson_7/task_1.py
+++ b/Lesson_7/task_1.py
@@ -14,28 +14,28 @@
class Matrix:
- def __init__(self, MyMatrix_1, MyMatrix_2, result):
+ def __init__(self, MyMatrix_1, MyMatrix_2):
self.MyMatrix_1 = MyMatrix_1
self.MyMatrix_2 = MyMatrix_2
- self.result = result
+ # self.result = result
def __add__(self):
result = [[0] * M for i in range(N)]
- self.MyMatrix_1 = []
- for i in range(N):
- row = input().split()
- for i in range(len(row)):
- row[i] = int(row[i])
- self.MyMatrix_1.append(row)
-
- self.MyMatrix_2 = []
- for i in range(M):
- row = input().split()
- for i in range(len(row)):
- row[i] = int(row[i])
- self.MyMatrix_2.append(row)
+ # MyMatrix_1 = []
+ # for i in range(N):
+ # row = input().split()
+ # for i in range(len(row)):
+ # row[i] = int(row[i])
+ # MyMatrix_1.append(row)
+ #
+ # MyMatrix_2 = []
+ # for i in range(M):
+ # row = input().split()
+ # for i in range(len(row)):
+ # row[i] = int(row[i])
+ # MyMatrix_2.append(row)
for i in range(len(self.MyMatrix_1)):
@@ -45,19 +45,17 @@ def __add__(self):
return str('\n'.join(['\t'.join([str(j) for j in i]) for i in result]))
def __str__(self):
- return str('\n'.join(['\t'.join([str(j) for j in i]) for i in result]))
+ return str('\n'.join(['\t'.join([str(j) for j in i]) for i in self.result]))
N = int(input('N = '))
M = int(input('M = '))
-# empty_matr = (matr.__add__())
-# n = int(input('Enter a number n: '))
-# total = (self.MyMatrix_1([]))
-# print(total.MyMatrix_1)
-# m = int(input('Enter a number m: '))
-my_matrix = Matrix([])
-# result = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
-
+my_matrix = Matrix([[3, 5, 32],
+ [2, 4, 6],
+ [-1, 64, -8]],
+ [[-8, 64, -1],
+ [6, 4, 2],
+ [32, 5, 3]])
print(my_matrix.__add__())
From 2b5721288ef53edd409bd88bdc70258dd0a2fe8d Mon Sep 17 00:00:00 2001
From: Pavel
Date: Tue, 29 Mar 2022 23:29:05 +0300
Subject: [PATCH 04/11] still the same...
---
Lesson_7/task_1.py | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/Lesson_7/task_1.py b/Lesson_7/task_1.py
index bcb9340..a8fcd09 100644
--- a/Lesson_7/task_1.py
+++ b/Lesson_7/task_1.py
@@ -45,10 +45,14 @@ def __add__(self):
return str('\n'.join(['\t'.join([str(j) for j in i]) for i in result]))
def __str__(self):
- return str('\n'.join(['\t'.join([str(j) for j in i]) for i in self.result]))
+ return str('\n'.join(['\t'.join([str(j) for j in i]) for i in result]))
N = int(input('N = '))
+
+# first_matrix = Matrix.__add__.MyMatrix_1 = []
+# print(first_matrix)
+
M = int(input('M = '))
my_matrix = Matrix([[3, 5, 32],
From dc1ec21991d1e22f41240e12abb15173d8036472 Mon Sep 17 00:00:00 2001
From: Pavel
Date: Thu, 31 Mar 2022 13:58:25 +0300
Subject: [PATCH 05/11] Everything seems to be in order.
---
Lesson_7/task_2.py | 59 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 59 insertions(+)
create mode 100644 Lesson_7/task_2.py
diff --git a/Lesson_7/task_2.py b/Lesson_7/task_2.py
new file mode 100644
index 0000000..57229aa
--- /dev/null
+++ b/Lesson_7/task_2.py
@@ -0,0 +1,59 @@
+# Реализовать проект расчета суммарного расхода ткани на производство одежды. Основная
+# сущность (класс) этого проекта — одежда, которая может иметь определенное название. К
+# типам одежды в этом проекте относятся пальто и костюм. У этих типов одежды существуют
+# параметры: размер (для пальто) и рост (для костюма). Это могут быть обычные числа: V и
+# H, соответственно.
+# Для определения расхода ткани по каждому типу одежды использовать формулы: для пальто
+# (V/6.5 + 0.5), для костюма (2*H + 0.3). Проверить работу этих методов на реальных данных.
+# Реализовать общий подсчет расхода ткани. Проверить на практике полученные на этом уроке
+# знания: реализовать абстрактные классы для основных классов проекта, проверить на
+# практике работу декоратора @property.
+
+class Cloth:
+ def __init__(self, size, height):
+ self.size = size
+ self.height = height
+
+ def get_cloth_amount_coat(self):
+ return self.size / 6.5 + 0.5
+
+ def get_cloth_amount_suit(self):
+ return self.height * 2 + 0.3
+
+ @property
+ def get_cloth_amount_total(self):
+ return str(f'The total amount of cloth needed for sewing products: \n'
+ f'{round((self.size / 6.5 + 0.5) + (self.height * 2 + 0.3), 2)}')
+
+
+class Coat(Cloth):
+ def __init__(self, size, height):
+ super().__init__(size, height)
+ self.cloth_amount_coat = round(self.size / 6.5 + 0.5, 2)
+
+ def __str__(self):
+ return f'The amount of cloth for sewing a coat is:\n'\
+ f' {self.cloth_amount_coat}'
+
+
+class Suit(Cloth):
+ def __init__(self, size, height):
+ super().__init__(size, height)
+ self.cloth_amount_suit = round(self.height * 2 + 0.3, 2)
+
+ def __str__(self):
+ return f'The amount of fabric for sewing a suit is:\n' \
+ f'{self.cloth_amount_suit}'
+
+
+# coat = Coat(4, 7)
+coat = Coat(int(input('Please enter your size: ')), int(input('Please enter your height: ')))
+print(coat)
+# print(coat.get_cloth_amount_coat)
+# print(coat.get_cloth_amount_total)
+
+# suit = Suit(4, 7)
+suit = Suit(int(input('Please enter your size: ')), int(input('Please enter your height: ')))
+print(suit)
+# print(suit.get_cloth_amount_suit)
+print(suit.get_cloth_amount_total)
From 9866cdeaedb5b5b51add9c39a04539dd419cf6c2 Mon Sep 17 00:00:00 2001
From: Pavel
Date: Thu, 31 Mar 2022 14:02:58 +0300
Subject: [PATCH 06/11] Still have some problems...
---
Lesson_7/task_1.py | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/Lesson_7/task_1.py b/Lesson_7/task_1.py
index a8fcd09..e902b49 100644
--- a/Lesson_7/task_1.py
+++ b/Lesson_7/task_1.py
@@ -14,33 +14,33 @@
class Matrix:
- def __init__(self, MyMatrix_1, MyMatrix_2):
- self.MyMatrix_1 = MyMatrix_1
- self.MyMatrix_2 = MyMatrix_2
+ def __init__(self, my_matrix_1, my_matrix_2):
+ self.my_matrix_1 = my_matrix_1
+ self.my_matrix_2 = my_matrix_2
# self.result = result
def __add__(self):
result = [[0] * M for i in range(N)]
- # MyMatrix_1 = []
+ # my_matrix_1 = []
# for i in range(N):
# row = input().split()
# for i in range(len(row)):
# row[i] = int(row[i])
- # MyMatrix_1.append(row)
+ # my_matrix_1.append(row)
#
- # MyMatrix_2 = []
+ # my_matrix_2 = []
# for i in range(M):
# row = input().split()
# for i in range(len(row)):
# row[i] = int(row[i])
- # MyMatrix_2.append(row)
+ # my_matrix_2.append(row)
- for i in range(len(self.MyMatrix_1)):
+ for i in range(len(self.my_matrix_1)):
- for j in range(len(self.MyMatrix_2[i])):
- result[i][j] = self.MyMatrix_1[i][j] + self.MyMatrix_2[i][j]
+ for j in range(len(self.my_matrix_2[i])):
+ result[i][j] = self.my_matrix_1[i][j] + self.my_matrix_2[i][j]
return str('\n'.join(['\t'.join([str(j) for j in i]) for i in result]))
@@ -50,7 +50,7 @@ def __str__(self):
N = int(input('N = '))
-# first_matrix = Matrix.__add__.MyMatrix_1 = []
+# first_matrix = Matrix.__add__.my_matrix_1 = []
# print(first_matrix)
M = int(input('M = '))
From a3955ed639c868a331059630d80f46aa60c8cef7 Mon Sep 17 00:00:00 2001
From: Pavel
Date: Thu, 31 Mar 2022 17:18:50 +0300
Subject: [PATCH 07/11] Everything seems to be ok...
---
Lesson_7/task_3.py | 82 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 82 insertions(+)
create mode 100644 Lesson_7/task_3.py
diff --git a/Lesson_7/task_3.py b/Lesson_7/task_3.py
new file mode 100644
index 0000000..9751be7
--- /dev/null
+++ b/Lesson_7/task_3.py
@@ -0,0 +1,82 @@
+# Реализовать программу работы с органическими клетками, состоящими из ячеек. Необходимо создать класс Клетка.
+# В его конструкторе инициализировать параметр, соответствующий количеству ячеек клетки (целое число).
+# В классе должны быть реализованы методы перегрузки арифметических операторов:
+# сложение (__add__()), вычитание (__sub__()), умножение (__mul__()), деление (__truediv__()).
+# Данные методы должны применяться только к клеткам и выполнять увеличение, уменьшение, умножение и целочисленное
+# (с округлением до целого) деление клеток, соответственно.
+# Сложение:
+# Объединение двух клеток. При этом число ячеек общей клетки должно равняться сумме ячеек исходных двух клеток.
+# Вычитание:
+# Участвуют две клетки. Операцию необходимо выполнять только если разность количества ячеек двух клеток больше нуля,
+# иначе выводить соответствующее сообщение.
+# Умножение:
+# Создаётся общая клетка из двух. Число ячеек общей клетки определяется как произведение количества ячеек этих двух
+# клеток.
+# Деление:
+# Создаётся общая клетка из двух. Число ячеек общей клетки определяется как целочисленное деление количества ячеек
+# этих двух клеток.
+#
+# В классе необходимо реализовать метод make_order(), принимающий экземпляр класса и количество ячеек в ряду.
+# Данный метод позволяет организовать ячейки по рядам. Метод должен возвращать строку вида *****\n*****\n*****...,
+# где количество ячеек между \n равно переданному аргументу. Если ячеек на формирование ряда не хватает,
+# то в последний ряд записываются все оставшиеся. Например, количество ячеек клетки равняется 12,
+# количество ячеек в ряду — 5. Тогда метод make_order() вернёт строку: *****\n*****\n**.
+# Или, количество ячеек клетки равняется 15, количество ячеек в ряду — 5.
+# Тогда метод make_order() вернёт строку: *****\n*****\n*****.
+# Подсказка: подробный список операторов для перегрузки доступен по ссылке.
+
+class Cell:
+ def __init__(self, amount):
+ self.amount = int(amount)
+
+ def __str__(self):
+ return f'{self.amount * "*"}'
+
+ def __add__(self, other): # '+'
+ return Cell(self.amount + other.amount)
+
+ def __sub__(self, other): # '-'
+ if self.amount - other.amount > 0:
+ return Cell(self.amount - other.amount)
+ else:
+ print('Negative value!')
+
+ def __mul__(self, other): # '*'
+ return Cell(self.amount * other.amount)
+
+ def __truediv__(self, other): # 'round(//)'
+ return Cell(round(self.amount // other.amount))
+
+ def make_order(self, cells_in_row):
+ row = ''
+ for i in range(int(self.amount / cells_in_row)):
+ row += f'{"*" * cells_in_row} \\n'
+ row += f'{"*" * (self.amount % cells_in_row)}'
+ return row
+
+
+print('The results of the option 1:')
+
+cells_1 = Cell(11)
+cells_2 = Cell(9)
+print('The number of * in cell 1: ', cells_1)
+print('The number of * in cell 2: ', cells_2)
+print('The result of adding: ', cells_1 + cells_2)
+print('The result of subtraction: ', cells_1 - cells_2)
+print('The result of multiplication: ', cells_1 * cells_2)
+print('The result of division: ', cells_1 / cells_2)
+print('Separation of cells:', cells_1.make_order(4))
+print('Separation of cells:', cells_2.make_order(3))
+
+print('The results of the option 2:')
+
+cells_1 = Cell(9)
+cells_2 = Cell(11)
+print('The number of * in cell 1: ', cells_1)
+print('The number of * in cell 2: ', cells_2)
+print('The result of adding: ', cells_1 + cells_2)
+print('The result of subtraction: ', cells_1 - cells_2)
+print('The result of multiplication: ', cells_1 * cells_2)
+print('The result of division: ', cells_1 / cells_2)
+print('Separation of cells:', cells_1.make_order(4))
+print('Separation of cells:', cells_2.make_order(3))
From 865d4a591de6091a865cd8fe9c3128f83510bd79 Mon Sep 17 00:00:00 2001
From: Pavel
Date: Thu, 31 Mar 2022 21:02:39 +0300
Subject: [PATCH 08/11] make some changes.
---
Lesson_7/task_1.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/Lesson_7/task_1.py b/Lesson_7/task_1.py
index e902b49..a0224ea 100644
--- a/Lesson_7/task_1.py
+++ b/Lesson_7/task_1.py
@@ -42,10 +42,10 @@ def __add__(self):
for j in range(len(self.my_matrix_2[i])):
result[i][j] = self.my_matrix_1[i][j] + self.my_matrix_2[i][j]
- return str('\n'.join(['\t'.join([str(j) for j in i]) for i in result]))
+ return '\n'.join('\t'.join(str(j) for j in i) for i in result)
def __str__(self):
- return str('\n'.join(['\t'.join([str(j) for j in i]) for i in result]))
+ return '\n'.join('\t'.join(str(j) for j in i) for i in self.result)
N = int(input('N = '))
From 16480db7577ca4b9e0a56e639a35c9e11659dbac Mon Sep 17 00:00:00 2001
From: Pavel
Date: Thu, 31 Mar 2022 21:08:12 +0300
Subject: [PATCH 09/11] make some changes.
---
Lesson_7/task_1.py | 2 ++
1 file changed, 2 insertions(+)
diff --git a/Lesson_7/task_1.py b/Lesson_7/task_1.py
index a0224ea..3c035ec 100644
--- a/Lesson_7/task_1.py
+++ b/Lesson_7/task_1.py
@@ -63,3 +63,5 @@ def __str__(self):
[32, 5, 3]])
print(my_matrix.__add__())
+
+
From 7882c5ae03d5fca450cadba1b8796b272006e40f Mon Sep 17 00:00:00 2001
From: Pavel
Date: Thu, 31 Mar 2022 21:09:00 +0300
Subject: [PATCH 10/11] Done.
---
Lesson_7/task_2.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Lesson_7/task_2.py b/Lesson_7/task_2.py
index 57229aa..c80409d 100644
--- a/Lesson_7/task_2.py
+++ b/Lesson_7/task_2.py
@@ -32,7 +32,7 @@ def __init__(self, size, height):
self.cloth_amount_coat = round(self.size / 6.5 + 0.5, 2)
def __str__(self):
- return f'The amount of cloth for sewing a coat is:\n'\
+ return f'The amount of cloth for sewing a coat is:\n' \
f' {self.cloth_amount_coat}'
From fa1d1e6546a553b99b3fdb44beebba2ac0bbc166 Mon Sep 17 00:00:00 2001
From: Pavel
Date: Thu, 31 Mar 2022 21:26:40 +0300
Subject: [PATCH 11/11] Done.
---
Lesson_7/task_3.py | 1 +
1 file changed, 1 insertion(+)
diff --git a/Lesson_7/task_3.py b/Lesson_7/task_3.py
index 9751be7..411334f 100644
--- a/Lesson_7/task_3.py
+++ b/Lesson_7/task_3.py
@@ -80,3 +80,4 @@ def make_order(self, cells_in_row):
print('The result of division: ', cells_1 / cells_2)
print('Separation of cells:', cells_1.make_order(4))
print('Separation of cells:', cells_2.make_order(3))
+