Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions task1.py
Original file line number Diff line number Diff line change
@@ -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)
23 changes: 23 additions & 0 deletions task2.py
Original file line number Diff line number Diff line change
@@ -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)
44 changes: 44 additions & 0 deletions task3.py
Original file line number Diff line number Diff line change
@@ -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)