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
21 changes: 21 additions & 0 deletions #1.py
Original file line number Diff line number Diff line change
@@ -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)])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

это самое короткое и элегантное решение, что я видел)



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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

лучше обзывать переменные поинформативнее

print(c)
29 changes: 29 additions & 0 deletions #2.py
Original file line number Diff line number Diff line change
@@ -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)
54 changes: 54 additions & 0 deletions #3.py
Original file line number Diff line number Diff line change
@@ -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='')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

да тут прямо можно влупить raise ValueError, чтобы неповадно было

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))