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
44 changes: 44 additions & 0 deletions hometask7/task1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env python
# nevl 2021

class Matrix:

def __init__(self, data):
if not type(data) is list or not type(data[0]) is list:
print('Not a matrix. Try again')
return

self.matrix_data = data

def __str__(self):
result = ''
for iter in self.matrix_data:
s = '['
for item in iter:
s += f'{item}\t'
result += f'{s}]\n'
return result

def __add__(self, other):
data = list()
# check shape
if len(self.matrix_data) != len(other.matrix_data) or len(self.matrix_data[0]) != len(other.matrix_data[0]):
return None

# calculate
for i in range(len(self.matrix_data)):
data.append(list())
for j in range(len(self.matrix_data[0])):
data[i].append(self.matrix_data[i][j] + other.matrix_data[i][j])

return Matrix(data)


if __name__ == '__main__':
mart1 = Matrix([[1, 2, 3], [3, 4, 5]])
print(mart1)

mart2 = Matrix([[1.1, 2.2, 3.3], [3.3, 4.4, 5.5]])
print(mart2)

print(mart1 + mart2)
44 changes: 44 additions & 0 deletions hometask7/task2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env python
# nevl 2021

from abc import ABC, abstractmethod


class dress(ABC):

def __init__(self, size):
self.size = size

@abstractmethod
def cloth_rate(self):
pass


class coat(dress):

@property
def cloth_rate(self):
return self.size / 6.5 + 0.5


class suit(dress):

@property
def cloth_rate(self):
return self.size * 2 + 0.3


if __name__ == '__main__':
c1 = coat(50)
print(c1.cloth_rate)

s1 = suit(1.75)
print(s1.cloth_rate)

c2 = coat(54)
print(c2.cloth_rate)

s2 = suit(1.85)
print(s2.cloth_rate)

print(f'Cloth for all dresses = {s1.cloth_rate + s2.cloth_rate + c1.cloth_rate + c2.cloth_rate}')
50 changes: 50 additions & 0 deletions hometask7/task3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env python
# nevl 2021

class Cell:

def __init__(self, count):
self.count = count

def __add__(self, other):
return Cell(self.count + other.count)

def __sub__(self, other):
t = self.count - other.count
if t < 0:
raise OverflowError
return Cell(t)

def __mul__(self, other):
return Cell(self.count * other.count)

def __truediv__(self, other):
return Cell(self.count // other.count)

def make_order(self, line_count):
s = ''
for _ in range(self.count // line_count):
s += '*'*line_count + '\n'
s += '*'*(self.count % line_count) + '\n'
return s


if __name__ == '__main__':
cell1 = Cell(31)
cell2 = Cell(35)
cell3 = Cell(27)

for it in [cell1, cell2, cell3]:
print(it.make_order(9))

try:
cell4 = cell1 - cell2
print(cell4.make_order(9))
except:
print('Error')

try:
cell5 = cell2 - cell3
print(cell5.make_order(9))
except:
print('Error')