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
33 changes: 33 additions & 0 deletions 1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
class Date():
def __init__(self, inner_date):
print('innit metod is work')
self.date = inner_date

@classmethod
def func_class_extract(cls, date):
print('class metod is work')
return list(int(i) for i in date.split('-'))

@staticmethod
def func_validator(inner):
print('static metod is work')
if 0 < inner[0] < 31:
print(f'day {inner[0]} ok')
else:
print(f'error day {inner[0]}')
if 0 < inner[1] < 13:
print(f'month {inner[1]} ok')
else:
print(f'error month {inner[0]}')
if 2000 < inner[2] < 2022:
print(f'year {inner[1]} ok and period 2000-2022')
else:
print(f'error year {inner[0]}')


Date('12-10-2021') # innit metod is work

res = Date.func_class_extract('12-10-2021') # class metod is work
print(res)

Date.func_validator(res) # static metod is work
40 changes: 40 additions & 0 deletions 2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@


class ZeroDiv(ZeroDivisionError):
def __init__(self, *args):
if args:
self.message = args[0]
else:
self.message = None

def __str__(self):
print('calling str')
if self.message:
return f'my zero division {self.message}'
else:
return f'my zero division'

# raise ZeroDiv

# one_in = int(input('введите значение делимого '))
def test_func():
one_value = 5
two_value = 0

try:
one = float(one_value)
two = float(two_value)
res = one/two
except ValueError:
print(f'некорректно введено значение')
except ZeroDivisionError as e:
print('перехват базового ZeroDivisionError')
raise ZeroDiv('test_zero_div')


if __name__ == '__main__':
try:
test_func()
except ZeroDiv:
print('перехват моего ZeroDiv')
print('ok')
31 changes: 31 additions & 0 deletions 3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
class My_exeption(ValueError):
def __init__(self, *argv):
self.message = argv[0]

def __str__(self):
return f'my error {self.message}'

def check_digit(self, li):
for num in li:
try:
print(f'{type(num)} num ')
z = float(num)
except ValueError:
raise My_exeption

li = []
while True:
in_value = input('введите значение для добавлени в список (q - для выхода) ')
if in_value == 'stop':
break
try:
try:
val = float(in_value)
except ValueError:
raise My_exeption('введено некорректное значение')
except My_exeption as e:
print(f'my extption {e}')
else:
li.append(val)

print(f' result list {li}')
120 changes: 120 additions & 0 deletions 4_5_6.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
from abc import abstractmethod


class Store():
def __init__(self):
self.full_dict = {}

def get_unit(self, unit, name):
unit.set_id(name)
self.full_dict[name] = unit


def move_to_office(self, id):
get_unit = self.full_dict.get(id)
if get_unit:
res = self.full_dict.pop(id)
print(f'{res} move to office')
return res
else:
print(f'NOT in store {id}')
return None


def check_store(self):
print(f'all in store {len(self.full_dict)} units')
if len(self.full_dict):
print(f'this units is:')
for name, cls in self.full_dict.items():
print(name, cls)



class Office_equipment():
@abstractmethod
def __init__(self, in_name, in_type):
self.name = in_name
self.type_is = in_type

def __str__(self):
return f'{self.name} {self.type_is}'

def to_print(self):
print('need define')

def get_name(self):
print(f'{self.name} - {self.type_is}')


class Printer(Office_equipment):
def __init__(self, name, type_is):
super().__init__(name, type_is)

@abstractmethod
def to_do(self):
print(f'{self.name} print pages')

def __str__(self):
return f'{self.name} {self.type_is}'


class Scaner(Office_equipment):
def __init__(self, name, type_is):
super().__init__(name, type_is)

def to_scan(self):
print(f'{self.name} scan to pages')


class MFU(Scaner, Printer):
def __init__(self, name, type_is):
Scaner.__init__(self, name, type_is)
Printer.__init__(self, name, type_is)
# self.id = prop

def to_do(self):
Scaner.to_scan(self)
Printer.to_print(self)

def get_inheritance(self):
print(f'full inheritance clases:\n {MFU.__mro__}')

@classmethod
def get_info_class(cls):
print(cls)

@abstractmethod
def check_info_mfu(cls):
print(cls.__mro__)
print(cls.__module__)
print(cls.__dict__)

@property
def get_id(self):
print(f'{self.name} have id {self.id}')

def set_id(self, in_id):
self.id = in_id


st = Store() # создаем склад
st.check_store() # проверяем склад

mfu = MFU('Xerox', 'R320') # у нас есть МФУ
MFU.get_info_class() # проверяем класс
MFU.check_info_mfu(MFU) # наследование, название модуля, информация о классе

st.get_unit(mfu, '1555') # добавляем мфу на склад присваивая id идентификационный номер
st.check_store()

mfu = st.move_to_office('1555') # склад передает МФУ в офис

mfu.to_do() # тестируем МФУ это принтер и сканер одновременно
mfu.get_name()
mfu.to_scan() # проверяем только сканирование
mfu.get_inheritance() # проверяем наследование
print(mfu.get_id) # проверяем id



mfu = st.move_to_office('1555') # пытаемся получить со склада такой-же МФУ
67 changes: 67 additions & 0 deletions 7.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
class Complex_digit():
def __init__(self, in_digit):
self.digit = in_digit

def check_negativ(self, digit):
return -int(digit) if digit.startswith('-') else int(digit)

def preparation(self, digit):
digit = digit.replace('i', '')
if digit.startswith('-'):
digit = digit[1:]
if '-' in digit:
a, b = digit.split('-')
return -int(a), -int(b)
else:
a, b = digit.split('+')
return -int(a), int(b)
else:
if '-' in digit:
a, b = digit.split('-')
return int(a), -int(b)
else:
a, b = digit.split('+')
return int(a), int(b)

def un_preparation(self, tup):
mark = '+' if tup[1] > 0 else ''
return f'{tup[0]}{mark}{tup[1]}i'

def __add__(self, two):
a, b = self.preparation(self.digit)
c, d = self.preparation(two.digit)

aa = a+c
bb = b+d

res = self.un_preparation((aa, bb))
print(res)
return Complex_digit(res)

def __mul__(self, two):
a, b = self.preparation(self.digit)
c, d = self.preparation(two.digit)

aa = a*c-b*d
bb = a*d+b*c

res = self.un_preparation((aa, bb))
print(res)
return Complex_digit(res)

#
a = Complex_digit('5-6i')
b = Complex_digit('-3+2i')
c = a + b
# print(c)
a = Complex_digit('1+3i')
b = Complex_digit('4-2i')
c = a * b
# print(c)
a = Complex_digit('3-2i')
b = Complex_digit('4+1i')
c = a * b
print(c)


import cmath # для работы с комплексными числами