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
62 changes: 62 additions & 0 deletions task_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import copy


def add_list(var_1, var_2):
new_list = []
if len(var_1) >= len(var_2):
for el in range(len(var_1)):
if el < len(var_2):
new_list.append(var_1[el] + var_2[el])
else:
new_list.append(var_1[el])
else:
new_list = add_list(var_2, var_1)
return new_list


class Matrix:

def __init__(self, arg):
self.matrix = []
for el in arg:
self.matrix.append(el)
self.len = len(arg)

def __str__(self):
string = ""
for el in self.matrix:
for i in el:
string += str(i) + " "
string.rstrip()
string = string + "\n"
return string

def __len__(self):
return self.len

def __add__(self, other):
new_matrix = []
if len(self.matrix) >= len(other.matrix):
for el in range(len(self.matrix)):
if el < len(other.matrix):
new_matrix.append(add_list(self.matrix[el], other.matrix[el]))
else:
new_matrix.append(self.matrix[el])
else:
for el in range(len(other.matrix)):
if el < len(self.matrix):
new_matrix.append(add_list(self.matrix[el], other.matrix[el]))
else:
new_matrix.append(other.matrix)
return Matrix(new_matrix)


my_matrix = Matrix([[12, 13, 15], [5, 46, 7], [23, 21], [14]])
my_matrix_2 = Matrix([[1, 2, 3], [4, 5, 6], [5], [55, 5, 12]])
my_matrix_3 = Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]])

print(my_matrix)
print(my_matrix_2)
print(my_matrix_3)
print(my_matrix + my_matrix_2 + my_matrix_3)

33 changes: 33 additions & 0 deletions task_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from abc import ABC, abstractmethod


class Clothes(ABC):

@abstractmethod
def consumption(self):
pass


class Coat(Clothes):

@property
def consumption(self):
return self.v / 6.5 + 0.5

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


class Suit(Clothes):

def consumption(self):
return self.h * 2 + 0.3

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


c = Coat(42)
s = Suit(44)
print(c.consumption)
print(s.consumption())
46 changes: 46 additions & 0 deletions task_3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
class Cell:
def __init__(self, nucleus):
self.nucleus = nucleus

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

def __sub__(self, other):
result_nucleus = self.nucleus - other.nucleus
if result_nucleus > 0:
return Cell(result_nucleus)
else:
print("Вычитание невозможно")
return Cell(0)

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

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

def make_order(self, arg):
string = ""
index = 1
for el in range(self.nucleus):
if index < arg:
string += "*"
index += 1
else:
string += "*\n"
index = 1
return string


c_1 = Cell(10)
c_2 = Cell(22)
c_3 = Cell(15)

print((c_1 + c_2).nucleus)
print((c_1 - c_2).nucleus)
print((c_2 + c_1).nucleus)
print((c_3 * c_2).nucleus)
print((c_2 / c_1).nucleus)

print(c_1.make_order(3))
print(c_3.make_order(4))